summaryrefslogtreecommitdiff
path: root/git-hooks
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@frugalware.org>2011-08-15 21:05:29 +0200
committerMiklos Vajna <vmiklos@frugalware.org>2011-08-15 21:08:09 +0200
commit8e4adb6038f8675d87d6766e62721f8e23fc91de (patch)
treed287d109ecef1fecf6b47ea8b15f509c9607ace7 /git-hooks
parent02d95370561c0b87e63ade341881c4e9dbe33e84 (diff)
git-hooks: whitespace problems are not errors in non-source files
Diffstat (limited to 'git-hooks')
-rwxr-xr-xgit-hooks/pre-commit11
1 files changed, 7 insertions, 4 deletions
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index bae5ff99bf94..d262fe108916 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -12,9 +12,9 @@ use Cwd;
$ENV{LC_ALL} = "C";
-sub check_whitespaces($)
+sub check_whitespaces($$)
{
- my ($h) = @_;
+ my ($h, $src_exts) = @_;
my $found_bad = 0;
my $filename;
@@ -22,6 +22,7 @@ sub check_whitespaces($)
my $lineno;
sub bad_line {
my ($why, $line) = @_;
+ if ($filename =~ /\.($src_exts)$/) {
if (!$found_bad) {
print STDERR "*\n";
print STDERR "* You have some suspicious patch lines:\n";
@@ -34,6 +35,7 @@ sub check_whitespaces($)
}
print STDERR "* $why (line $lineno)\n";
print STDERR "$filename:$lineno:$line\n";
+ }
}
open( FILES, "git-diff-index -p -M --cached $h |" ) || die "Cannot run git diff-index.";
while (<FILES>) {
@@ -134,12 +136,13 @@ while (my $file = <FILES>) {
# be strict about tabs - we don't want them at all, setup your editor
# correctly ;-)
my $err_ext = "";
+my $src_exts = "c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml";
open( FILES, "git diff-index --cached --name-only $against |" ) || die "Cannot run git diff-index.";
while ( my $file = <FILES> ) {
chomp( $file );
if ( $file ne "GNUmakefile" &&
- $file =~ /\.(c|cpp|cxx|h|hrc|hxx|idl|inl|java|map|MK|pmk|pl|pm|sdi|sh|src|tab|xcu|xml)$/) {
+ $file =~ /\.($src_exts)$/) {
open( F, "git diff-index -p --cached $against -- '$file' |" );
while ( my $line = <F> ) {
if ( $line =~ /^\+ *\t/ ) {
@@ -186,7 +189,7 @@ EOM
}
# fix whitespace in code
-check_whitespaces( $against );
+check_whitespaces( $against, $src_exts );
# check the rest of the files
my $filter_patches=`git diff-index --check --cached $against -- | sed '/\.\(diff\|patch\):/,/.*/d'`;