Skip to content
Snippets Groups Projects
Commit 5d74c95c authored by Stan Hu's avatar Stan Hu Committed by Oswaldo Ferreira
Browse files

Check that source and target branch exist

This ensures the return value is consistent if the source and/or
branch do not exist.
parent 54d64ec9
No related branches found
No related tags found
Loading
......@@ -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 @@ def initialize(new_start_project, new_start_ref_name)
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 @@
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 @@ def merge_to_ref
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment