Commit e01c692a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Remove tag with git hooks

parent 99ac0935
...@@ -196,16 +196,14 @@ class Repository ...@@ -196,16 +196,14 @@ class Repository
true true
end end
# TODO: why we don't pass user here? def rm_tag(user, tag_name)
def rm_tag(tag_name)
before_remove_tag before_remove_tag
tag = find_tag(tag_name)
begin GitOperationService.new(user, self).rm_tag(tag)
rugged.tags.delete(tag_name)
after_remove_tag
true true
rescue Rugged::ReferenceError
false
end
end end
def ref_names def ref_names
...@@ -401,6 +399,11 @@ class Repository ...@@ -401,6 +399,11 @@ class Repository
repository_event(:remove_tag) repository_event(:remove_tag)
end end
# Runs code after removing a tag.
def after_remove_tag
expire_tags_cache
end
def before_import def before_import
expire_content_cache expire_content_cache
end end
......
...@@ -7,7 +7,7 @@ class DeleteTagService < BaseService ...@@ -7,7 +7,7 @@ class DeleteTagService < BaseService
return error('No such tag', 404) return error('No such tag', 404)
end end
if repository.rm_tag(tag_name) if repository.rm_tag(current_user, tag_name)
release = project.releases.find_by(tag: tag_name) release = project.releases.find_by(tag: tag_name)
release.destroy if release release.destroy if release
......
...@@ -15,7 +15,7 @@ class GitOperationService ...@@ -15,7 +15,7 @@ class GitOperationService
def rm_branch(branch) def rm_branch(branch)
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch.name ref = Gitlab::Git::BRANCH_REF_PREFIX + branch.name
oldrev = branch.dereferenced_target.id oldrev = branch.target
newrev = Gitlab::Git::BLANK_SHA newrev = Gitlab::Git::BLANK_SHA
update_ref_in_hooks(ref, newrev, oldrev) update_ref_in_hooks(ref, newrev, oldrev)
...@@ -36,6 +36,16 @@ class GitOperationService ...@@ -36,6 +36,16 @@ class GitOperationService
end end
end end
def rm_tag(tag)
ref = Gitlab::Git::TAG_REF_PREFIX + tag.name
oldrev = tag.target
newrev = Gitlab::Git::BLANK_SHA
update_ref_in_hooks(ref, newrev, oldrev) do
repository.rugged.tags.delete(tag_name)
end
end
# Whenever `source_branch_name` is passed, if `branch_name` doesn't exist, # Whenever `source_branch_name` is passed, if `branch_name` doesn't exist,
# it would be created from `source_branch_name`. # it would be created from `source_branch_name`.
# If `source_project` is passed, and the branch doesn't exist, # If `source_project` is passed, and the branch doesn't exist,
......
...@@ -1419,9 +1419,10 @@ describe Repository, models: true do ...@@ -1419,9 +1419,10 @@ describe Repository, models: true do
describe '#rm_tag' do describe '#rm_tag' do
it 'removes a tag' do it 'removes a tag' do
expect(repository).to receive(:before_remove_tag) expect(repository).to receive(:before_remove_tag)
expect(repository.rugged.tags).to receive(:delete).with('v1.1.0')
repository.rm_tag('v1.1.0') repository.rm_tag(create(:user), 'v1.1.0')
expect(repository.find_tag('v1.1.0')).to be_nil
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment