3 # A 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
6 # if it wants to stop the commit.
14 sub check_whitespaces
($)
17 my $src_limited = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml";
18 my $src_full = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|mk|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml";
22 my $reported_filename = "";
25 my ($why, $line, $file_filter) = @_;
26 if (!defined $file_filter || $filename =~ /\.($file_filter)$/) {
29 print STDERR
"* You have some suspicious patch lines:\n";
33 if ($reported_filename ne $filename) {
34 print STDERR
"* In $filename\n";
35 $reported_filename = $filename;
37 print STDERR
"* $why (line $lineno)\n";
38 print STDERR
"$filename:$lineno:$line\n";
41 open( FILES
, "git-diff-index -p -M --cached $h |" ) || die "Cannot run git diff-index.";
43 if (m
|^diff
--git a
/(.*) b/\
1$|) {
47 if (/^@@ -\S+ \+(\d+)/) {
59 bad_line
("trailing whitespace", $_ , $src_limited);
62 bad_line
("indent SP followed by a TAB", $_, $src_limited);
64 if (/^(?:[<>=]){7}$/) {
65 bad_line
("unresolved merge conflict", $src_full);
77 # Initial commit: diff against an empty tree object
78 my $against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
79 if ( system( "git rev-parse --verify HEAD >/dev/null 2>&1" ) == 0 ) {
83 # If you want to allow non-ascii filenames set this variable to true.
84 my $allownonascii=`git config hooks.allownonascii`;
86 # Cross platform projects tend to avoid non-ascii filenames; prevent
87 # them from being added to the repository. We exploit the fact that the
88 # printable range starts at the space character and ends with tilde.
89 if ( $allownonascii ne "true" &&
90 # Note that the use of brackets around a tr range is ok here, (it's
91 # even required, for portability to Solaris 10's /usr/bin/tr), since
92 # the square bracket bytes happen to fall in the designated range.
93 `git diff --cached --name-only --diff-filter=A -z $against | \
94 LC_ALL=C tr -d '[ -~]\\0'` ne "" )
97 Error: Attempt to add a non-ascii file name.
99 This can cause problems if you want to work
100 with people on other platforms.
102 To be portable it is advisable to rename the file ...
104 If you know what you are doing you can disable this
107 git config hooks.allownonascii true
113 # fix whitespace in code
114 check_whitespaces
( $against);
118 # vi:set shiftwidth=4 expandtab: