diff options
Diffstat (limited to 'git-hooks')
-rwxr-xr-x | git-hooks/pre-commit | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index cee3a7f4ac8a..8192e5840c56 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -58,6 +58,18 @@ sub check_and_fix_whitespace($) my $line_no = 0; my $line_max = -1; + my $stash = ""; + + # any not staged changes to stash away? + system( "git update-index -q --refresh" ); + if ( `git diff --name-only --` ) { + my $fd; + ( $fd, $stash ) = mkstemp( "/tmp/unstaged-changes-XXXXXX" ); + close( $fd ); + # this will keep the staged changes + system( "git diff > $stash" ); + system( "git checkout ." ); + } open( IN, "git diff-index -p --no-prefix --cached $head -- |" ) || die "Cannot get git diff-index"; while ( my $line = <IN> ) { if ( $line =~ /^\+\+\+ (.*)/ ) { @@ -80,6 +92,10 @@ sub check_and_fix_whitespace($) } fix_whitespace( $file, \%lines ); close( IN ); + if ($stash) { + system( "git apply < $stash" ); + unlink( $stash ); + } } # Do the work :-) |