summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-12-26 10:24:16 -0800
committerOswaldo Ferreira <>2019-04-18 22:01:51 -0300
commit26653eb0359002e9991bf5089c5505b566125f26 (patch)
treeb4a10088456c99fc36b0bd378143ae8abc8a822c /spec/lib
parent9ec37d3dc1c1969be743a0c283242dc462a8f466 (diff)
downloadgitlab-ce-26653eb0359002e9991bf5089c5505b566125f26.tar.gz
Don't create a temp reference for branch comparisons within project
A temp reference is only needed to fetch a branch from another project, as in the case for forked repositories. For branch comparisons within the same project, we can just use the existing branch names to do the comparison. Relates to https://gitlab.com/gitlab-org/gitlab-ce/issues/38689#note_126107862
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 778950c95e4..85c45ea4183 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1966,6 +1966,42 @@ describe Gitlab::Git::Repository, :seed_helper do
end
end
+ describe '#compare_source_branch' do
+ context 'within same repository' do
+ it 'does not create a temp ref' do
+ expect(repository).not_to receive(:fetch_source_branch!)
+ expect(repository).not_to receive(:delete_refs)
+
+ compare = repository.compare_source_branch('master', repository, 'feature', straight: false)
+ expect(compare).to be_a(Gitlab::Git::Compare)
+ expect(compare.commits.count).to be > 0
+ end
+
+ it 'returns nil when source ref does not exist' do
+ compare = repository.compare_source_branch('master', repository, 'non-existent-branch', straight: false)
+
+ expect(compare).to be_nil
+ end
+ end
+
+ context 'with different repositories' do
+ it 'creates a temp ref' do
+ expect(repository).to receive(:fetch_source_branch!).and_call_original
+ expect(repository).to receive(:delete_refs).and_call_original
+
+ compare = repository.compare_source_branch('master', mutable_repository, 'feature', straight: false)
+ expect(compare).to be_a(Gitlab::Git::Compare)
+ expect(compare.commits.count).to be > 0
+ end
+
+ it 'returns nil when source ref does not exist' do
+ compare = repository.compare_source_branch('master', mutable_repository, 'non-existent-branch', straight: false)
+
+ expect(compare).to be_nil
+ end
+ end
+ end
+
describe '#checksum' do
it 'calculates the checksum for non-empty repo' do
expect(repository.checksum).to eq '51d0a9662681f93e1fee547a6b7ba2bcaf716059'