Commit 2e5ff778 authored by Sean McGivern's avatar Sean McGivern Committed by Alejandro Rodríguez

Merge branch 'pass-correct-tag-target-to-post-receive' into 'master'

Pass correct tag target to post-receive hook when creating tag via UI

Fixes #24437

See merge request !7556
parent 9d40f83d
...@@ -176,11 +176,18 @@ class Repository ...@@ -176,11 +176,18 @@ class Repository
options = { message: message, tagger: user_to_committer(user) } if message options = { message: message, tagger: user_to_committer(user) } if message
GitHooksService.new.execute(user, path_to_repo, oldrev, target, ref) do
rugged.tags.create(tag_name, target, options) rugged.tags.create(tag_name, target, options)
tag = find_tag(tag_name)
GitHooksService.new.execute(user, path_to_repo, oldrev, tag.target, ref) do
# we already created a tag, because we need tag SHA to pass correct
# values to hooks
end end
find_tag(tag_name) tag
rescue GitHooksService::PreReceiveError
rugged.tags.delete(tag_name)
raise
end end
def rm_branch(user, branch_name) def rm_branch(user, branch_name)
......
---
title: Pass correct tag target to post-receive hook when creating tag via UI
merge_request: 7556
author:
...@@ -1354,6 +1354,28 @@ describe Repository, models: true do ...@@ -1354,6 +1354,28 @@ describe Repository, models: true do
repository.add_tag(user, '8.5', 'master', 'foo') repository.add_tag(user, '8.5', 'master', 'foo')
end end
it 'does not create a tag when a pre-hook fails' do
allow_any_instance_of(Gitlab::Git::Hook).to receive(:trigger).and_return([false, ''])
expect do
repository.add_tag(user, '8.5', 'master', 'foo')
end.to raise_error(GitHooksService::PreReceiveError)
repository.expire_tags_cache
expect(repository.find_tag('8.5')).to be_nil
end
it 'passes tag SHA to hooks' do
spy = GitHooksService.new
allow(GitHooksService).to receive(:new).and_return(spy)
allow(spy).to receive(:execute).and_call_original
tag = repository.add_tag(user, '8.5', 'master', 'foo')
expect(spy).to have_received(:execute).
with(anything, anything, anything, tag.target, anything)
end
it 'returns a Gitlab::Git::Tag object' do it 'returns a Gitlab::Git::Tag object' do
tag = repository.add_tag(user, '8.5', 'master', 'foo') tag = repository.add_tag(user, '8.5', 'master', 'foo')
......
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