Commit 0eae158c authored by Rémy Coutable's avatar Rémy Coutable

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
parents cd17f804 b2c73fde
......@@ -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?
......
---
title: Look for new branches more carefully
merge_request: 29761
author:
type: fixed
......@@ -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
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