Commit 9b24f18f authored by Ryan Jackson's avatar Ryan Jackson
Browse files

Improved handling of trivial merges in gitmail

Use 'git diff-tree --no-commit-id --cc' on merge commits to determine if
there are any differences between the merge commit and its parents.
This is the case if any new files were hand-modified or added as part of
the merge (such as when conflicts were resolved).  If git-diff-tree
produces no output, the merge was trivial.

If the merge was trivial, the commit message is checked for an empty
body.  If empty, the commit is skipped when generating the email.  This
way if the committer documents the merge in some way (list of changes,
reason for the merge, etc.) the email includes that information.
parent 8c6807e0
......@@ -48,8 +48,9 @@ my $debug = get_config("debug",undef);
my $testmode = undef;
#
# If set, try to hide trivial merges (i.e., ones with standard subject
# line and no body text). Ugly hack.
# If set, hide trivial merges (those where no diff hunks needed to be modified
# as part of the merge). Trivial merges that have a non-empty commit message
# are still shown in case the committer decided to document the merge.
#
my $hide_trivial_merges = get_config("hidetrivialmerges",undef);
......@@ -692,6 +693,12 @@ sub commit_mail($\@$@) {
my $is_merge = 0;
my $body_lines = 0;
my $subject;
my @diff_lines;
# This is a bit of a hack. It assumes that the output
# of git-show will not change. We could use --pretty
# to produce exactly the format we want, but since we've
# already called git-show we'll just use that.
for (@body) {
$is_merge = 1 if (/^Merge:/);
if (/^ /) {
......@@ -702,12 +709,17 @@ sub commit_mail($\@$@) {
}
}
}
if ($is_merge) {
@diff_lines = `$GIT diff-tree --no-commit-id --cc $rev`;
}
if ($is_merge && $body_lines == 0 &&
$subject =~ /^ +Merge (?:remote )?branch '[^']+'(?: of .*)?$/){
if ($is_merge && !@diff_lines && !$body_lines) {
# We have a trivial merge, i.e. no hunks were modified as
# part of the merge. We still want to show the commit if
# the commit message is non-standard.
next;
}
}
if ($separate_mail) {
......
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