summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2019-06-18 15:20:33 +0000
committerRémy Coutable <remy@rymai.me>2019-06-18 15:20:33 +0000
commit0eae158c15eb047a58a3f51db0c32f1b841b4b60 (patch)
treece01e8e7efa4c3f336ff9f856918932cffa175ab
parentcd17f804d51751870f71e3bab57feeb9ab75da38 (diff)
parentb2c73fde791ebac6c2cc615fce19294190b05609 (diff)
downloadgitlab-ce-0eae158c15eb047a58a3f51db0c32f1b841b4b60.tar.gz
Merge branch '59257-find-new-branches-harder' into 'master'
Look for new branches more carefully Closes #59257 See merge request gitlab-org/gitlab-ce!29761
-rw-r--r--app/services/git/branch_hooks_service.rb8
-rw-r--r--changelogs/unreleased/59257-find-new-branches-harder.yml5
-rw-r--r--spec/services/git/branch_hooks_service_spec.rb34
3 files changed, 46 insertions, 1 deletions
diff --git a/app/services/git/branch_hooks_service.rb b/app/services/git/branch_hooks_service.rb
index 4aee48f22e7..c41f445c3c4 100644
--- a/app/services/git/branch_hooks_service.rb
+++ b/app/services/git/branch_hooks_service.rb
@@ -105,8 +105,14 @@ module Git
CreateGpgSignatureWorker.perform_async(signable, project.id)
end
+ # It's not sufficient to just check for a blank SHA as it's possible for the
+ # branch to be pushed, but for the `post-receive` hook to never run:
+ # https://gitlab.com/gitlab-org/gitlab-ce/issues/59257
def creating_branch?
- Gitlab::Git.blank_ref?(params[:oldrev])
+ strong_memoize(:creating_branch) do
+ Gitlab::Git.blank_ref?(params[:oldrev]) ||
+ !project.repository.branch_exists?(branch_name)
+ end
end
def updating_branch?
diff --git a/changelogs/unreleased/59257-find-new-branches-harder.yml b/changelogs/unreleased/59257-find-new-branches-harder.yml
new file mode 100644
index 00000000000..631eaa22ef0
--- /dev/null
+++ b/changelogs/unreleased/59257-find-new-branches-harder.yml
@@ -0,0 +1,5 @@
+---
+title: Look for new branches more carefully
+merge_request: 29761
+author:
+type: fixed
diff --git a/spec/services/git/branch_hooks_service_spec.rb b/spec/services/git/branch_hooks_service_spec.rb
index b5694628269..23be400059e 100644
--- a/spec/services/git/branch_hooks_service_spec.rb
+++ b/spec/services/git/branch_hooks_service_spec.rb
@@ -344,4 +344,38 @@ describe Git::BranchHooksService do
end
end
end
+
+ describe 'New branch detection' do
+ let(:branch) { 'fix' }
+
+ context 'oldrev is the blank SHA' do
+ let(:oldrev) { Gitlab::Git::BLANK_SHA }
+
+ it 'is treated as a new branch' do
+ expect(service).to receive(:branch_create_hooks)
+
+ service.execute
+ end
+ end
+
+ context 'oldrev is set' do
+ context 'Gitaly does not know about the branch' do
+ it 'is treated as a new branch' do
+ allow(project.repository).to receive(:branch_names) { [] }
+
+ expect(service).to receive(:branch_create_hooks)
+
+ service.execute
+ end
+ end
+
+ context 'Gitaly knows about the branch' do
+ it 'is not treated as a new branch' do
+ expect(service).not_to receive(:branch_create_hooks)
+
+ service.execute
+ end
+ end
+ end
+ end
end