Skip to content

Commit 9dfd381

Browse files
committed
Dangerfile: error about merge commits.
Addressed to #537
1 parent 145ac3e commit 9dfd381

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: Dangerfile

+14-6
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,20 @@ end
670670

671671
commits = git.commits.size
672672
if commits > 1
673-
warn(
674-
"danger check: pull request contains #{commits} commits while most of the cases it should have only one.\n"\
675-
"If it's not a special case you should squash commits into single one.\n"\
676-
"You can read how to do it here: https://davidwalsh.name/squash-commits-git\n"\
677-
"But be careful because **it can destroy** all your changes!"
678-
)
673+
if git.commits.any? { |c| c.message =~ /^Merge branch/ || c.message =~ /^Merge remote-tracking branch/ }
674+
fail(
675+
"danger check: pull request contains merge commits! "\
676+
"Please, rebase your branch to get rid of them:\n"\
677+
"`git rebase master #{github.branch_for_head}`"
678+
)
679+
else
680+
warn(
681+
"danger check: pull request contains #{commits} commits while most of the cases it should have only one.\n"\
682+
"If it's not a special case you should squash commits into single one.\n"\
683+
"You can read how to do it here: https://davidwalsh.name/squash-commits-git\n"\
684+
"But be careful because **it can destroy** all your changes!"
685+
)
686+
end
679687
end
680688

681689
all_checks_passed = violation_report[:errors].empty? && violation_report[:warnings].empty? && violation_report[:messages].empty?

0 commit comments

Comments
 (0)