BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c5553ce7
Commit
c5553ce7
authored
Aug 30, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `git update-ref --stdin -z` to delete refs
parent
86149a82
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
5 deletions
+53
-5
repository.rb
app/models/repository.rb
+1
-1
after_import_service.rb
app/services/projects/after_import_service.rb
+1
-1
repository.rb
lib/gitlab/git/repository.rb
+16
-2
cleanup.rake
lib/tasks/gitlab/cleanup.rake
+1
-1
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+34
-0
No files found.
app/models/repository.rb
View file @
c5553ce7
...
@@ -1246,6 +1246,6 @@ class Repository
...
@@ -1246,6 +1246,6 @@ class Repository
yield
commit
(
sha
)
yield
commit
(
sha
)
ensure
ensure
rugged
.
references
.
delete
(
tmp_ref
)
if
tmp_ref
delete_refs
(
tmp_ref
)
if
tmp_ref
end
end
end
end
app/services/projects/after_import_service.rb
View file @
c5553ce7
...
@@ -9,7 +9,7 @@ module Projects
...
@@ -9,7 +9,7 @@ module Projects
def
execute
def
execute
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
repository
.
delete_refs
(
garbage_refs
)
repository
.
delete_refs
(
*
garbage_refs
)
end
end
rescue
Projects
::
HousekeepingService
::
LeaseTaken
=>
e
rescue
Projects
::
HousekeepingService
::
LeaseTaken
=>
e
Rails
.
logger
.
info
(
Rails
.
logger
.
info
(
...
...
lib/gitlab/git/repository.rb
View file @
c5553ce7
...
@@ -17,6 +17,7 @@ module Gitlab
...
@@ -17,6 +17,7 @@ module Gitlab
NoRepository
=
Class
.
new
(
StandardError
)
NoRepository
=
Class
.
new
(
StandardError
)
InvalidBlobName
=
Class
.
new
(
StandardError
)
InvalidBlobName
=
Class
.
new
(
StandardError
)
InvalidRef
=
Class
.
new
(
StandardError
)
InvalidRef
=
Class
.
new
(
StandardError
)
GitError
=
Class
.
new
(
StandardError
)
class
<<
self
class
<<
self
# Unlike `new`, `create` takes the storage path, not the storage name
# Unlike `new`, `create` takes the storage path, not the storage name
...
@@ -598,8 +599,21 @@ module Gitlab
...
@@ -598,8 +599,21 @@ module Gitlab
rugged
.
branches
.
delete
(
branch_name
)
rugged
.
branches
.
delete
(
branch_name
)
end
end
def
delete_refs
(
ref_names
)
def
delete_refs
(
*
ref_names
)
ref_names
.
each
{
|
ref
|
rugged
.
references
.
delete
(
ref
)
}
instructions
=
ref_names
.
map
do
|
ref
|
"delete
#{
ref
}
\x00\x00
"
end
command
=
%W[
#{
Gitlab
.
config
.
git
.
bin_path
}
update-ref --stdin -z]
message
,
status
=
Gitlab
::
Popen
.
popen
(
command
,
path
)
do
|
stdin
|
stdin
.
write
(
instructions
.
join
)
end
unless
status
.
zero?
raise
GitError
.
new
(
"Could not delete refs
#{
ref_names
}
:
#{
message
}
"
)
end
end
end
# Create a new branch named **ref+ based on **stat_point+, HEAD by default
# Create a new branch named **ref+ based on **stat_point+, HEAD by default
...
...
lib/tasks/gitlab/cleanup.rake
View file @
c5553ce7
...
@@ -111,7 +111,7 @@ namespace :gitlab do
...
@@ -111,7 +111,7 @@ namespace :gitlab do
next
unless
id
>
max_iid
next
unless
id
>
max_iid
project
.
deployments
.
find
(
id
).
create_ref
project
.
deployments
.
find
(
id
).
create_ref
rugged
.
references
.
delete
(
ref
)
project
.
repository
.
delete_refs
(
ref
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
c5553ce7
...
@@ -433,6 +433,40 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -433,6 +433,40 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#delete_refs'
do
before
(
:all
)
do
@repo
=
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_MUTABLE_REPO_PATH
,
''
)
end
it
'deletes the ref'
do
@repo
.
delete_refs
(
'refs/heads/feature'
)
expect
(
@repo
.
rugged
.
references
[
'refs/heads/feature'
]).
to
be_nil
end
it
'deletes all refs'
do
refs
=
%w[refs/heads/wip refs/tags/v1.1.0]
@repo
.
delete_refs
(
*
refs
)
refs
.
each
do
|
ref
|
expect
(
@repo
.
rugged
.
references
[
ref
]).
to
be_nil
end
end
it
'raises an error if it failed'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
and_return
([
'Error'
,
1
])
expect
do
@repo
.
delete_refs
(
'refs/heads/fix'
)
end
.
to
raise_error
(
Gitlab
::
Git
::
Repository
::
GitError
)
end
after
(
:all
)
do
FileUtils
.
rm_rf
(
TEST_MUTABLE_REPO_PATH
)
ensure_seeds
end
end
describe
"#refs_hash"
do
describe
"#refs_hash"
do
let
(
:refs
)
{
repository
.
refs_hash
}
let
(
:refs
)
{
repository
.
refs_hash
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment