Prevent case sensitive commit
[git/jr.git] / templates / hooks--pre-commit
blobcf7bd53f38b9375abfffb7174783a95b02f3aef3
1 #!/bin/sh
3 # An example hook script to verify what is about to be committed.
4 # Called by git-commit with no arguments. The hook should
5 # exit with non-zero status after issuing an appropriate message if
6 # it wants to stop the commit.
8 # To enable this hook, make this file executable.
10 # Detect case challenges
12 case_challenge=`git ls-files | tr A-Z a-z | sort | uniq -d`
13 if [ -n "$case_challenge" ]
14 then
15 echo >&2 "index contains file names differing only in case."
16 echo >&2 "lowercase names follow:"
17 echo >&2 "$case_challenge"
18 exit 1
21 # This is slightly modified from Andrew Morton's Perfect Patch.
22 # Lines you introduce should not have trailing whitespace.
23 # Also check for an indentation that has SP before a TAB.
25 if git-rev-parse --verify HEAD 2>/dev/null
26 then
27 git-diff-index -p -M --cached HEAD --
28 else
29 # NEEDSWORK: we should produce a diff with an empty tree here
30 # if we want to do the same verification for the initial import.
32 fi |
33 perl -e '
34 my $found_bad = 0;
35 my $filename;
36 my $reported_filename = "";
37 my $lineno;
38 sub bad_line {
39 my ($why, $line) = @_;
40 if (!$found_bad) {
41 print STDERR "*\n";
42 print STDERR "* You have some suspicious patch lines:\n";
43 print STDERR "*\n";
44 $found_bad = 1;
46 if ($reported_filename ne $filename) {
47 print STDERR "* In $filename\n";
48 $reported_filename = $filename;
50 print STDERR "* $why (line $lineno)\n";
51 print STDERR "$filename:$lineno:$line\n";
53 while (<>) {
54 if (m|^diff --git a/(.*) b/\1$|) {
55 $filename = $1;
56 next;
58 if (/^@@ -\S+ \+(\d+)/) {
59 $lineno = $1 - 1;
60 next;
62 if (/^ /) {
63 $lineno++;
64 next;
66 if (s/^\+//) {
67 $lineno++;
68 chomp;
69 if (/\s$/) {
70 bad_line("trailing whitespace", $_);
72 if (/^\s* \t/) {
73 bad_line("indent SP followed by a TAB", $_);
75 if (/^([<>])\1{6} |^={7}$/) {
76 bad_line("unresolved merge conflict", $_);
80 exit($found_bad);