diff options
-rw-r--r-- | lib/gitlab/git/repository.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 848a782446a..ec4b4a4c993 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1376,7 +1376,7 @@ module Gitlab def rugged_fetch_source_branch(source_repository, source_branch, local_ref) with_repo_branch_commit(source_repository, source_branch) do |commit| if commit - write_ref(local_ref, commit.sha) + write_ref(local_ref, commit.sha, force: true) true else false diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 03a9cc488ca..65144dc7f24 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1643,6 +1643,21 @@ describe Gitlab::Git::Repository, seed_helper: true do expect(repository.commit(local_ref).sha).to eq(expected_oid) end end + + context 'when the ref exists locally' do + let(:source_branch) { 'master' } + let(:expected_oid) { SeedRepo::LastCommit::ID } + + it 'writes the ref' do + # Sanity check: the commit should already exist + expect(repository.commit(expected_oid)).not_to be_nil + + # Make sure the ref exists + expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) + # Writing it once more should succeed + expect(repository.fetch_source_branch!(source_repository, source_branch, local_ref)).to eq(true) + end + end end context 'when the branch does not exist' do |