Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.10;
- use strict;
- use warnings;
- use File::Basename;
- use Term::ANSIColor qw(colored);
- $ENV{LOG} = "test";
- my $nb_errors = 0;
- for my $filepath (`git diff --cached --name-only`) {
- chomp $filepath;
- next if not -f $filepath;
- my @file_infos = fileparse( $filepath, qr/\.[^.]*/ );
- if ( $file_infos[2] =~ /^.pl|^.pm$/ ) {
- system(qq{/usr/bin/perl -wc $filepath}) == 0
- or say "\n" and $nb_errors++;
- }
- elsif ( $file_infos[2] =~ /^.tt$/ ) {
- #TODO
- }
- elsif ( $file_infos[2] =~ /^.js$/ ) {
- #TODO
- }
- }
- my $filepath;
- for my $l ( split '\n', `git diff-index -p -M --cached HEAD` ) {
- if ( $l =~ /^diff --git a\/([^ ]*) .*$/ ) {
- $filepath = $1;
- }
- if ( $l =~ /console.log/ ) {
- say colored( "$filepath contains console.log ($l)", 'red' );
- $nb_errors++;
- }
- elsif ( $l =~ /^\+ *warn Data::Dumper::Dumper / ) {
- say colored( "$filepath contains warn Data::Dumper::Dumper ($l)",
- 'red' );
- $nb_errors++;
- }
- # This one could be uncommented when Koha will have the Logger module
- elsif ( $l =~ /^\+ *warn / ) {
- say "$filepath contains warn ($l)";
- $nb_errors++;
- }
- elsif ( $l =~ m/^<<<<<<</ or $l =~ m/^>>>>>>>/ or $l =~ m/^=======/ ) {
- say colored( "$filepath contains $& ($l)", 'red' );
- }
- elsif ( $l =~ /(\+|-)\s*use/ ) {
- say colored( "Patch add or remove a use in $filepath: $l", 'red' );
- say
- "You should run xt/find-undefined-subroutines.pl to check if nothing is broken";
- $nb_errors++;
- }
- }
- if ($nb_errors) {
- say "\nAre you sure you want to commit ?";
- say "You can commit with the --no-verify argument";
- exit 1;
- }
- exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement