Skip to content

Commit d37fd03

Browse files
author
Junio C Hamano
committed
[PATCH] pre-commit sample hook: do not barf on the initial import
The example hook barfs on the initial import. Ideally it should produce a diff from an empty tree, but for now let's stop at squelching the bogus error message. Often an initial import involves tons of badly formatted files from foreign SCM, so not complaining about them like this patch does might actually be a better idea than enforcing the "Perfect Patch" format on them. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 181dc77 commit d37fd03

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

templates/hooks--pre-commit

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
# This is slightly modified from Andrew Morton's Perfect Patch.
1111
# Lines you introduce should not have trailing whitespace.
1212
# Also check for an indentation that has SP before a TAB.
13+
14+
if git-rev-parse --verify HEAD 2>/dev/null
15+
then
16+
git-diff-index -p -M --cached HEAD
17+
else
18+
# NEEDSWORK: we should produce a diff with an empty tree here
19+
# if we want to do the same verification for the initial import.
20+
:
21+
fi |
1322
perl -e '
14-
my $fh;
1523
my $found_bad = 0;
1624
my $filename;
1725
my $reported_filename = "";
@@ -31,8 +39,7 @@ perl -e '
3139
print STDERR "* $why (line $lineno)\n";
3240
print STDERR "$filename:$lineno:$line\n";
3341
}
34-
open $fh, "-|", qw(git-diff-index -p -M --cached HEAD);
35-
while (<$fh>) {
42+
while (<>) {
3643
if (m|^diff --git a/(.*) b/\1$|) {
3744
$filename = $1;
3845
next;

0 commit comments

Comments
 (0)