If you are merging from somebody else, and the merge needs manual conflict resolution, eventually you will complete it by calling "git commit". Now, if the tree you are merging in introduces whitespace breakages, what should we do? Currently the situation is: - If the merge does not conflict, you do not have to complete it by running "git commit", and whitespace breakages will be accepted as part of the merge. - If you need to run "git commit", however, pre-commit hook can kick in. The sample pre-commit hook will complain. I think the semantics of "merge" is "I trust him and take his changes"; accepting whitespace broken tree, just like we do in non-conflicting case, is fine. Even though the sample hook is, eh, just "sample", we should make it consistent. So perhaps something like this patch would take us in the right direction. Note that this I think still has issues when amending a merge. From inside hooks, I do not think you can detect that you are called to handle amending. Worse yet, I suspect that "HEAD" may not be the right thing to compare with when amending, in which case further fixups (even if we do not want to deal with this whitespace check issues) is required. --- diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit index b25dce6..10b3743 100644 --- a/templates/hooks--pre-commit +++ b/templates/hooks--pre-commit @@ -11,6 +11,12 @@ # Lines you introduce should not have trailing whitespace. # Also check for an indentation that has SP before a TAB. +in_merge=0 +if test -f $GIT_DIR/MERGE_HEAD +then + in_merge=1 +fi + if git-rev-parse --verify HEAD 2>/dev/null then git-diff-index -p -M --cached HEAD -- @@ -24,6 +30,7 @@ perl -e ' my $filename; my $reported_filename = ""; my $lineno; + my $in_merge = $ARGV[0]; sub bad_line { my ($why, $line) = @_; if (!$found_bad) { @@ -39,7 +46,7 @@ perl -e ' print STDERR "* $why (line $lineno)\n"; print STDERR "$filename:$lineno:$line\n"; } - while (<>) { + while (<STDIN>) { if (m|^diff --git a/(.*) b/\1$|) { $filename = $1; next; @@ -55,16 +62,18 @@ perl -e ' if (s/^\+//) { $lineno++; chomp; - if (/\s$/) { - bad_line("trailing whitespace", $_); - } - if (/^\s* \t/) { - bad_line("indent SP followed by a TAB", $_); + if (!$in_merge) { + if (/\s$/) { + bad_line("trailing whitespace", $_); + } + if (/^\s* \t/) { + bad_line("indent SP followed by a TAB", $_); + } } - if (/^([<>])\1{6} |^={7}$/) { + if ($in_merge && /^([<>])\1{6} |^={7}$/) { bad_line("unresolved merge conflict", $_); } } } exit($found_bad); -' +' "$in_merge" -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html