Created
December 1, 2010 15:36
-
-
Save nrh/723644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl -w | |
use Perl6::Slurp; | |
my $status = slurp '-|', 'git status'; | |
# only want what is going to be commited | |
$status =~ s/Changed but not updated.*$//s; | |
my @dirty = | |
grep { !file_is_tidy($_) } # not tidy | |
grep {/\.(pl|pod|pm|t)$/} # perl file | |
map {/(?:modified|new file):\s+(\S+)/} # to be commited | |
split "\n", $status; | |
exit 0 unless @dirty; # Alles gut | |
warn "following files are not tidy, aborting commit\n", map "\t$_\n" => @dirty; | |
exit 1; | |
### utility functions ############################################### | |
sub file_is_tidy | |
{ | |
my $file = shift; | |
my $original = slurp $file; | |
my $tidied = slurp '-|', 'perltidy', $file, '-st'; | |
return $original eq $tidied; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment