summaryrefslogtreecommitdiff
path: root/git-hooks
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2011-05-17 13:15:03 +0200
committerDavid Tardon <dtardon@redhat.com>2011-05-17 14:22:58 +0200
commit121cb7d8a74e198c63abdfcf4c239dea97505ce7 (patch)
treed920e712dfa9021cc6e7548cb3a1b139a13a6b8b /git-hooks
parent5f5a7519db07bce91a82fdb472eeaffd807f5eb8 (diff)
do not overwrite file if no whitespace was stripped
Diffstat (limited to 'git-hooks')
-rwxr-xr-xgit-hooks/pre-commit12
1 files changed, 9 insertions, 3 deletions
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit
index 8a316fdb70fe..f71ad6f98214 100755
--- a/git-hooks/pre-commit
+++ b/git-hooks/pre-commit
@@ -21,12 +21,15 @@ sub fix_whitespace($$) {
open( IN, "$file" ) || die "Cannot open $file for reading";
my ( $out, $tmpfile ) = mkstemp( "/tmp/whitespace-fixing-XXXXXX" );
+ my $changed = 0;
my $line_no = 1;
while ( my $line = <IN> ) {
if ( $lines->{$line_no} && $line =~ /^(.*[^ \t])[ \t]+$/ ) {
+ $changed = 1;
print $out "$1\n";
}
elsif ( $lines->{$line_no} && $line =~ /^[ \t]+$/ ) {
+ $changed = 1;
print $out "\n";
}
else {
@@ -37,10 +40,13 @@ sub fix_whitespace($$) {
close( $out );
close( IN );
- move( $tmpfile, $file ) or die "Cannot move '$tmpfile' to '$file'";
+ if ( $changed )
+ {
+ move( $tmpfile, $file ) or die "Cannot move '$tmpfile' to '$file'";
- system( "git add $file" );
- print "Fixed whitespace in '$file'\n";
+ system( "git add $file" );
+ print "Fixed whitespace in '$file'\n";
+ }
}
# go through the patch and collect lines to fix