[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>
Junio C Hamano committed
Jan 29, 2006 at 14:52 UTC
d37fd03222ad6b38aa6e237f5f191238c0544850
1 file changed
+10
-3
templates/hooks--pre-commit
+10
-3
@@ -10,8 +10,16 @@
10
# This is slightly modified from Andrew Morton's Perfect Patch.
11
# Lines you introduce should not have trailing whitespace.
12
# 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 |
22
perl -e '
14
- my $fh;
23
my $found_bad = 0;
24
my $filename;
25
my $reported_filename = "";
@@ -31,8 +39,7 @@ perl -e '
39
print STDERR "* $why (line $lineno)\n";
40
print STDERR "$filename:$lineno:$line\n";
41
}
34
- open $fh, "-|", qw(git-diff-index -p -M --cached HEAD);
35
- while (<$fh>) {
42
+ while (<>) {
43
if (m|^diff --git a/(.*) b/\1$|) {
44
$filename = $1;
45
next;