From b1f541a8e9b6b3384104367f2f75cb11b8d14a5d Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Wed, 20 Dec 2017 14:10:18 +0100 Subject: Use `force: true` for fetch_source_branch --- lib/gitlab/git/repository.rb | 2 +- spec/lib/gitlab/git/repository_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1