Skip to content

Instantly share code, notes, and snippets.

@nrh
Created December 1, 2010 15:36
Show Gist options
  • Save nrh/723644 to your computer and use it in GitHub Desktop.
Save nrh/723644 to your computer and use it in GitHub Desktop.
#!/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