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|ui|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|ui|xcu|xml";
22 my $reported_filename = "";
26 my ($why, $line, $file_filter) = @_;
27 if (!defined $file_filter || $filename =~ /\.($file_filter)$/)
32 print STDERR
"* You have some suspicious patch lines:\n";
36 if ($reported_filename ne $filename)
38 print STDERR
"* In $filename\n";
39 $reported_filename = $filename;
41 print STDERR
"* $why (line $lineno)\n";
42 print STDERR
"$filename:$lineno:$line\n";
45 open( FILES
, "git-diff-index -p -M --cached $h |" ) || die "Cannot run git diff-index.";
48 if (m
|^diff
--git a
/(.*) b/\
1$|)
53 if (/^@@ -\S+ \+(\d+)/)
69 bad_line
("trailing whitespace", $_ , $src_limited);
73 bad_line
("indent with Tab", $_, $src_limited);
77 bad_line
("unresolved merge conflict", $src_full);
81 bad_line
("temporary debug in commit", $_, $src_limited);
83 if (/<property name="use_markup">True<\/property
>/)
85 bad_line
("use font attributes instead of use-markup", $_, $src_limited);
97 # Initial commit: diff against an empty tree object
98 my $against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
99 if ( system( "git rev-parse --verify HEAD >/dev/null 2>&1" ) == 0 )
104 # If you want to allow non-ascii filenames set this variable to true.
105 my $allownonascii=`git config hooks.allownonascii`;
107 # Cross platform projects tend to avoid non-ascii filenames; prevent
108 # them from being added to the repository. We exploit the fact that the
109 # printable range starts at the space character and ends with tilde.
110 if ( $allownonascii ne "true" &&
111 # Note that the use of brackets around a tr range is ok here, (it's
112 # even required, for portability to Solaris 10's /usr/bin/tr), since
113 # the square bracket bytes happen to fall in the designated range.
114 `git diff --cached --name-only --diff-filter=A -z $against | \
115 LC_ALL=C tr -d '[ -~]\\0'` ne "" )
118 Error: Attempt to add a non-ascii file name.
120 This can cause problems if you want to work
121 with people on other platforms.
123 To be portable it is advisable to rename the file ...
125 If you know what you are doing you can disable this
128 git config hooks.allownonascii true
135 open( FILES
, "git diff --cached --name-only --diff-filter=A -z $against |" ) || die "Cannot run git diff-index.";
138 my $size = `git cat-file -s :$_`;
139 # For now let's say large is 500KB
141 if ($size > $limit * 1024)
143 print "Error: Attempt to add a large file: $_, pleasy try to fit into $limit KB.\n";
148 # fix whitespace in code
149 check_whitespaces
( $against);
153 # vi:set shiftwidth=4 expandtab: