diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2016-11-18 17:20:48 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2016-11-18 17:20:48 +0300 |
commit | ae51774bc45d2e15ccc61b01a30d1b588f179f85 (patch) | |
tree | 0085a8b0d0434784e13dece71329307d01577c80 /app | |
parent | 492ead3f715d2bfefad25190d98803f41307021f (diff) |
Pass correct tag target to post-receive hook when creating tag via UI
We need to handle annotated tags that are created via GitLab UI.
Annotated tags have their own SHA. We have to pass this SHA to
post-receive hook to mirror what happens when someone creates
an annotated tag in their local repository and pushes it via
command line.
In order to obtain tag SHA we first have to create it. This is
a bit confusing because we create the tag before executing
pre-hooks, but there is no way to create a tag outside the
repository. If pre-hooks fail we have to clean up after ourselves.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 146424d2b1c..31be06be50c 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -176,11 +176,18 @@ class Repository 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 - find_tag(tag_name) + tag + rescue GitHooksService::PreReceiveError + rugged.tags.delete(tag_name) + raise end def rm_branch(user, branch_name) |