diff --git a/CHANGELOG-EE b/CHANGELOG-EE index d5fabbb0cb9877b3d256c0760bfbdac59d089a9b..fa48f15ae86a6c3b3ed931437ad7864dc1164337 100644 --- a/CHANGELOG-EE +++ b/CHANGELOG-EE @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) - Rename Git Hooks to Push Rules + - Fix merge request 500 when first commit does not have a parent. !525 v 8.9.4 - Improve how File Lock feature works with nested items. !497 diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index c56844cd73a00aaec7426f99ed3e98a241062cc3..81d6a151fc5d3e848a406166f97bd395bd79b48a 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -629,7 +629,8 @@ def in_locked_state end def source_sha_parent - source_project.repository.commit(first_commit.sha).parents.first.sha + parents = source_project.repository.commit(first_commit.sha).parents + parents.first.sha unless parents.empty? end def ff_merge_possible? diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 1ff436fb67c22348179bf75267737e73cf1d7a58..8ff5fdd199cc0337cee5acc1415eccb7bc0992c7 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -331,9 +331,21 @@ end end - describe "#source_sha_parent" do - it "returns the sha of the parent commit of the first commit in the MR" do - expect(subject.source_sha_parent).to eq("ae73cb07c9eeaf35924a10f713b364d32b2dd34f") + describe '#source_sha_parent' do + it 'returns the sha of the parent commit of the first commit in the MR' do + expect(subject.source_sha_parent).to eq('ae73cb07c9eeaf35924a10f713b364d32b2dd34f') + end + + it 'returns nil when the first commit in the MR has no parents' do + allow_any_instance_of(Commit).to receive(:parents).and_return([]) + + expect(subject.source_sha_parent).to be_nil + end + + it 'does not raise an error when the first commit in the MR has no parents' do + allow_any_instance_of(Commit).to receive(:parents).and_return([]) + + expect { subject.source_sha_parent }.not_to raise_error end end