summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-11-02 11:39:12 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2016-11-03 10:14:41 +0100
commitc847335ed683f633b78c243fc78a4c15c765c4e7 (patch)
treee724e2ccdab723b11b01691e43aa0f37da20414f
parentfabc3d7bdec27a45349c5c6f38683ca5c6fe8817 (diff)
downloadgitlab-ce-idea-to-production-demo.tar.gz
Don't execute git hooks if you create branch as part of other changeidea-to-production-demo
Currently, our procedure for adding a commit requires us to execute `CreateBranchService` before file creation. It's OK, but also we do execute `git hooks` (the `PostReceive` sidekiq job) as part of this process. However, this hook is execute before the file is actually committed, so the ref is updated. Secondly, we do execute a `git hooks` after committing file and updating ref. This results in duplicate `PostReceive` jobs, where the first one is completely invalid. This change makes the branch creation, something that is intermediate step of bigger process (file creation or update, commit cherry pick or revert) to not execute git hooks.
-rw-r--r--app/models/repository.rb8
-rw-r--r--app/services/commits/change_service.rb2
-rw-r--r--app/services/create_branch_service.rb4
-rw-r--r--app/services/files/base_service.rb2
4 files changed, 10 insertions, 6 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 4da1933c189..ff7f1a3d638 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -143,14 +143,18 @@ class Repository
tags.find { |tag| tag.name == name }
end
- def add_branch(user, branch_name, target)
+ def add_branch(user, branch_name, target, with_hooks: true)
oldrev = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
target = commit(target).try(:id)
return false unless target
- GitHooksService.new.execute(user, path_to_repo, oldrev, target, ref) do
+ if with_hooks
+ GitHooksService.new.execute(user, path_to_repo, oldrev, target, ref) do
+ update_ref!(ref, target, oldrev)
+ end
+ else
update_ref!(ref, target, oldrev)
end
diff --git a/app/services/commits/change_service.rb b/app/services/commits/change_service.rb
index 1c82599c579..2d4c9788d02 100644
--- a/app/services/commits/change_service.rb
+++ b/app/services/commits/change_service.rb
@@ -55,7 +55,7 @@ module Commits
return success if repository.find_branch(new_branch)
result = CreateBranchService.new(@project, current_user)
- .execute(new_branch, @target_branch, source_project: @source_project)
+ .execute(new_branch, @target_branch, source_project: @source_project, with_hooks: false)
if result[:status] == :error
raise ChangeError, "There was an error creating the source branch: #{result[:message]}"
diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb
index 757fc35a78f..a6a3461e17b 100644
--- a/app/services/create_branch_service.rb
+++ b/app/services/create_branch_service.rb
@@ -1,7 +1,7 @@
require_relative 'base_service'
class CreateBranchService < BaseService
- def execute(branch_name, ref, source_project: @project)
+ def execute(branch_name, ref, source_project: @project, with_hooks: true)
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
unless valid_branch
@@ -26,7 +26,7 @@ class CreateBranchService < BaseService
repository.find_branch(branch_name)
else
- repository.add_branch(current_user, branch_name, ref)
+ repository.add_branch(current_user, branch_name, ref, with_hooks: with_hooks)
end
if new_branch
diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb
index 9bd4bd464f7..1802b932e03 100644
--- a/app/services/files/base_service.rb
+++ b/app/services/files/base_service.rb
@@ -74,7 +74,7 @@ module Files
end
def create_target_branch
- result = CreateBranchService.new(project, current_user).execute(@target_branch, @source_branch, source_project: @source_project)
+ result = CreateBranchService.new(project, current_user).execute(@target_branch, @source_branch, source_project: @source_project, with_hooks: false)
unless result[:status] == :success
raise_error("Something went wrong when we tried to create #{@target_branch} for you: #{result[:message]}")