summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2017-12-20 14:10:18 +0100
committerAhmad Sherif <me@ahmadsherif.com>2017-12-20 14:48:44 +0100
commitb1f541a8e9b6b3384104367f2f75cb11b8d14a5d (patch)
tree9ae0be7ff2a5aa384f74e25735c754984d2b138a
parentcc8ff768d712cabf7311802cec026654f005b88b (diff)
downloadgitlab-ce-fix-rugged-fetch-source-branch.tar.gz
Use `force: true` for fetch_source_branchfix-rugged-fetch-source-branch
-rw-r--r--lib/gitlab/git/repository.rb2
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb15
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