Check that source and target branch exist
This ensures the return value is consistent if the source and/or branch do not exist.
This commit is contained in:
parent
54d64ec9f6
commit
5d74c95c98
|
@ -3,7 +3,7 @@
|
|||
require 'securerandom'
|
||||
|
||||
# Compare 2 refs for one repo or between repositories
|
||||
# and return Gitlab::Git::Compare object that responds to commits and diffs
|
||||
# and return Compare object that responds to commits and diffs
|
||||
class CompareService
|
||||
attr_reader :start_project, :start_ref_name
|
||||
|
||||
|
@ -15,7 +15,7 @@ class CompareService
|
|||
def execute(target_project, target_ref, base_sha: nil, straight: false)
|
||||
raw_compare = target_project.repository.compare_source_branch(target_ref, start_project.repository, start_ref_name, straight: straight)
|
||||
|
||||
return unless raw_compare
|
||||
return unless raw_compare && raw_compare.base && raw_compare.head
|
||||
|
||||
Compare.new(raw_compare,
|
||||
target_project,
|
||||
|
|
|
@ -82,7 +82,7 @@ describe Projects::CompareController do
|
|||
show_request
|
||||
|
||||
expect(response).to be_success
|
||||
expect(assigns(:diffs).diff_files.to_a).to eq([])
|
||||
expect(assigns(:diffs)).to eq([])
|
||||
expect(assigns(:commits)).to eq([])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1977,7 +1977,7 @@ describe Gitlab::Git::Repository, :seed_helper do
|
|||
expect(compare.commits.count).to be > 0
|
||||
end
|
||||
|
||||
it 'returns nil when source ref does not exist' do
|
||||
it 'returns empty commits when source ref does not exist' do
|
||||
compare = repository.compare_source_branch('master', repository, 'non-existent-branch', straight: false)
|
||||
|
||||
expect(compare.commits).to be_empty
|
||||
|
|
Loading…
Reference in New Issue