Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
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
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
5 deletions
+53
-5
app/models/repository.rb
app/models/repository.rb
+1
-1
app/services/projects/after_import_service.rb
app/services/projects/after_import_service.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+16
-2
lib/tasks/gitlab/cleanup.rake
lib/tasks/gitlab/cleanup.rake
+1
-1
spec/lib/gitlab/git/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
yield
commit
(
sha
)
ensure
rugged
.
references
.
delete
(
tmp_ref
)
if
tmp_ref
delete_refs
(
tmp_ref
)
if
tmp_ref
end
end
app/services/projects/after_import_service.rb
View file @
c5553ce7
...
...
@@ -9,7 +9,7 @@ module Projects
def
execute
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
repository
.
delete_refs
(
garbage_refs
)
repository
.
delete_refs
(
*
garbage_refs
)
end
rescue
Projects
::
HousekeepingService
::
LeaseTaken
=>
e
Rails
.
logger
.
info
(
...
...
lib/gitlab/git/repository.rb
View file @
c5553ce7
...
...
@@ -17,6 +17,7 @@ module Gitlab
NoRepository
=
Class
.
new
(
StandardError
)
InvalidBlobName
=
Class
.
new
(
StandardError
)
InvalidRef
=
Class
.
new
(
StandardError
)
GitError
=
Class
.
new
(
StandardError
)
class
<<
self
# Unlike `new`, `create` takes the storage path, not the storage name
...
...
@@ -598,8 +599,21 @@ module Gitlab
rugged
.
branches
.
delete
(
branch_name
)
end
def
delete_refs
(
ref_names
)
ref_names
.
each
{
|
ref
|
rugged
.
references
.
delete
(
ref
)
}
def
delete_refs
(
*
ref_names
)
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
# 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
next
unless
id
>
max_iid
project
.
deployments
.
find
(
id
).
create_ref
rugged
.
references
.
delete
(
ref
)
project
.
repository
.
delete_refs
(
ref
)
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
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
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