summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-02-22 15:46:39 +0100
committerRémy Coutable <remy@rymai.me>2016-02-22 15:46:39 +0100
commitfbbd362d1534fe664000cd6dabf3bfae78db9347 (patch)
tree1fe6ef45cc658c8360930fa412b9fcc978a50d05
parentf51d8af5a72e563b3ea87668b6f4981dcbcdcd14 (diff)
downloadgitlab-ce-fix/13631-error-with-merged-mr.tar.gz
Ensure we don't check a commit's description for revert message if it has no descriptionfix/13631-error-with-merged-mr
-rw-r--r--app/models/commit.rb2
-rw-r--r--spec/models/commit_spec.rb34
2 files changed, 35 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index b99abb540ea..3224f5457f0 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -232,7 +232,7 @@ class Commit
end
def reverts_commit?(commit)
- description.include?(commit.revert_description)
+ description? && description.include?(commit.revert_description)
end
def merge_commit?
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index ecf37b40c58..fe839790c31 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -118,4 +118,38 @@ eos
it { expect(data[:modified]).to eq([".gitmodules"]) }
it { expect(data[:removed]).to eq([]) }
end
+
+ describe '#reverts_commit?' do
+ let(:another_commit) { double(:commit, revert_description: "This reverts commit #{commit.sha}") }
+
+ it { expect(commit.reverts_commit?(another_commit)).to be_falsy }
+
+ context 'commit has no description' do
+ before { allow(commit).to receive(:description?).and_return(false) }
+
+ it { expect(commit.reverts_commit?(another_commit)).to be_falsy }
+ end
+
+ context 'another_commit\'s description does not revert commit' do
+ before { allow(commit).to receive(:description).and_return("Foo Bar") }
+
+ it { expect(commit.reverts_commit?(another_commit)).to be_falsy }
+ end
+
+ context 'another_commit\'s description reverts commit' do
+ before { allow(commit).to receive(:description).and_return("Foo #{another_commit.revert_description} Bar") }
+
+ it { expect(commit.reverts_commit?(another_commit)).to be_truthy }
+ end
+
+ context 'another_commit\'s description reverts merged merge request' do
+ before do
+ revert_description = "This reverts merge request !foo123"
+ allow(another_commit).to receive(:revert_description).and_return(revert_description)
+ allow(commit).to receive(:description).and_return("Foo #{another_commit.revert_description} Bar")
+ end
+
+ it { expect(commit.reverts_commit?(another_commit)).to be_truthy }
+ end
+ end
end