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);
68 bad_line
("temporary debug in commit", $_, $src_limited);
80 # Initial commit: diff against an empty tree object
81 my $against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
82 if ( system( "git rev-parse --verify HEAD >/dev/null 2>&1" ) == 0 ) {
86 # If you want to allow non-ascii filenames set this variable to true.
87 my $allownonascii=`git config hooks.allownonascii`;
89 # Cross platform projects tend to avoid non-ascii filenames; prevent
90 # them from being added to the repository. We exploit the fact that the
91 # printable range starts at the space character and ends with tilde.
92 if ( $allownonascii ne "true" &&
93 # Note that the use of brackets around a tr range is ok here, (it's
94 # even required, for portability to Solaris 10's /usr/bin/tr), since
95 # the square bracket bytes happen to fall in the designated range.
96 `git diff --cached --name-only --diff-filter=A -z $against | \
97 LC_ALL=C tr -d '[ -~]\\0'` ne "" )
100 Error: Attempt to add a non-ascii file name.
102 This can cause problems if you want to work
103 with people on other platforms.
105 To be portable it is advisable to rename the file ...
107 If you know what you are doing you can disable this
110 git config hooks.allownonascii true
116 # fix whitespace in code
117 check_whitespaces
( $against);
121 # vi:set shiftwidth=4 expandtab: