Commit b0535009 authored by Stan Hu's avatar Stan Hu

Fix MergeRequestService erroring out on deleted branch

When a branch is deleted, the push commit IDs is an empty array.
The previous change would attempt to call `[].exists?`, which is
invalid. Fix this by returning `MergeRequestDiffCommit.none` instead.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53853
parent a407bba8
......@@ -142,7 +142,7 @@ class MergeRequestDiff < ActiveRecord::Base
end
def commits_by_shas(shas)
return [] unless shas.present?
return MergeRequestDiffCommit.none unless shas.present?
merge_request_diff_commits.where(sha: shas)
end
......
......@@ -2650,6 +2650,10 @@ describe MergeRequest do
end
describe '#includes_any_commits?' do
it 'returns false' do
expect(subject.includes_any_commits?([])).to be_falsey
end
it 'returns false' do
expect(subject.includes_any_commits?([Gitlab::Git::BLANK_SHA])).to be_falsey
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment