Commit 733db645 authored by Stan Hu's avatar Stan Hu

Fix PostReceive failing for project mirrors missing local branch

For some reason, if the local branch is deleted but the remote branch
exists, PostReceive fails with a nil error.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50843
parent 9f04b5a1
......@@ -42,7 +42,7 @@ module EE
branch_commit = commit("refs/heads/#{branch_name}")
upstream_commit = commit("refs/remotes/#{MIRROR_REMOTE}/#{branch_name}")
if upstream_commit
if branch_commit && upstream_commit
!raw_repository.ancestor?(branch_commit.id, upstream_commit.id)
else
false
......@@ -53,7 +53,7 @@ module EE
branch_commit = commit("refs/heads/#{branch_name}")
upstream_commit = commit("refs/remotes/#{remote_ref}/#{branch_name}")
if upstream_commit
if branch_commit && upstream_commit
!raw_repository.ancestor?(upstream_commit.id, branch_commit.id)
else
false
......@@ -64,7 +64,7 @@ module EE
branch_commit = commit("refs/heads/#{branch_name}")
upstream_commit = commit("refs/remotes/#{MIRROR_REMOTE}/#{branch_name}")
if upstream_commit
if branch_commit && upstream_commit
ancestor?(branch_commit.id, upstream_commit.id)
else
false
......
---
title: Fix PostReceive failing for project mirrors missing local branch
merge_request: 8495
author:
type: fixed
require 'spec_helper'
describe GitPushService do
include RepoHelpers
set(:user) { create(:user) }
let(:blankrev) { Gitlab::Git::BLANK_SHA }
let(:oldrev) { sample_commit.parent_id }
let(:newrev) { sample_commit.id }
let(:ref) { 'refs/heads/master' }
context 'with pull project' do
set(:project) { create(:project, :repository, :mirror) }
subject do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
context 'deleted branch' do
let(:newrev) { blankrev }
it 'handles when remote branch exists' do
allow(project.repository).to receive(:commit).and_call_original
allow(project.repository).to receive(:commit).with("master").and_return(nil)
expect(project.repository).to receive(:commit).with("refs/remotes/upstream/master").and_return(sample_commit)
subject.execute
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