Bug 40858: Search merge conflict on files part of the git index
Same as bug 34303 and bug 33743, our test suite must parse/process files that are part of the index, not all the other files. It's currently failing on kohadev-db-request.txt that is owned by root. But it's not part of the Koha codebase, this file should not be tested. There were also node_modules and po files that were processed. Test plan: prove t/00-merge-conflict-markers.t must now return gren Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
36bd4bd7b4
commit
cc72eabc5f
|
|
@ -132,11 +132,19 @@ Builds a Git exclude pattern for a given file type based on the context provided
|
|||
=cut
|
||||
|
||||
sub build_git_exclude {
|
||||
my ( $self, $filetype ) = @_;
|
||||
return $self->{context} && exists $exceptions->{$filetype}->{ $self->{context} }
|
||||
my ( $self, $filetype, $extensions ) = @_;
|
||||
my $exclude_list = q{};
|
||||
if ($filetype) {
|
||||
$exclude_list .=
|
||||
$self->{context} && exists $exceptions->{$filetype}->{ $self->{context} }
|
||||
? join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype}->{ $self->{context} } } ) )
|
||||
: q{};
|
||||
}
|
||||
if ($extensions) {
|
||||
$exclude_list .= join( " ", map( "':(exclude)*.$_'", @$extensions ) );
|
||||
}
|
||||
return $exclude_list;
|
||||
}
|
||||
|
||||
=head2 ls_perl_files
|
||||
|
||||
|
|
@ -219,6 +227,22 @@ sub ls_css_files {
|
|||
return @files;
|
||||
}
|
||||
|
||||
=head2 ls_all_files
|
||||
|
||||
my @files = $file_manager->ls_all_files([$extension_list_to_exclude]);
|
||||
|
||||
Lists all files in the repository. Accept a list of extension to exclude.
|
||||
|
||||
=cut
|
||||
|
||||
sub ls_all_files {
|
||||
my ( $self, $extensions ) = @_;
|
||||
my $cmd = sprintf q{git ls-files %s}, $self->build_git_exclude( undef, $extensions );
|
||||
my @files = qx{$cmd};
|
||||
chomp for @files;
|
||||
return @files;
|
||||
}
|
||||
|
||||
=head2 get_filetype
|
||||
|
||||
my $filetype = $file_manager->get_filetype($filename);
|
||||
|
|
|
|||
|
|
@ -16,45 +16,26 @@
|
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More;
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 2;
|
||||
use File::Spec;
|
||||
use File::Find;
|
||||
use IO::File;
|
||||
|
||||
my @failures;
|
||||
find(
|
||||
{
|
||||
bydepth => 1,
|
||||
no_chdir => 1,
|
||||
wanted => sub {
|
||||
my $file = $_;
|
||||
use Koha::Devel::Files;
|
||||
|
||||
return if $file =~ /\.(ico|jpg|gif|ogg|pdf|png|psd|swf|zip|.*\~)$/;
|
||||
return unless -f $file;
|
||||
my $dev_files = Koha::Devel::Files->new( { context => 'full' } );
|
||||
my @files = $dev_files->ls_all_files( [qw(ico jpg gif ogg pdf png psd)] );
|
||||
|
||||
my @name_parts = File::Spec->splitpath($file);
|
||||
my %dirs = map { $_ => 1 } File::Spec->splitdir( $name_parts[1] );
|
||||
return if exists $dirs{'.git'};
|
||||
plan tests => scalar @files + 1;
|
||||
|
||||
my $fh = IO::File->new( $file, 'r' );
|
||||
my $marker_found = 0;
|
||||
for my $file (@files) {
|
||||
my $has_conflicts;
|
||||
open my $fh, '<', $file or die "Cannot open $file: $!";
|
||||
while ( my $line = <$fh> ) {
|
||||
|
||||
# could check for ^=====, but that's often used in text files
|
||||
$marker_found++ if $line =~ m|^<<<<<<|;
|
||||
$marker_found++ if $line =~ m|^>>>>>>|;
|
||||
last if $marker_found;
|
||||
# Could check for ^=====, but that's often used in text files
|
||||
if ( $line =~ /^<<<<<<<|^>>>>>>>/ ) {
|
||||
$has_conflicts = 1;
|
||||
}
|
||||
}
|
||||
ok( !$has_conflicts, "$file should not contain merge conflict markers" );
|
||||
close $fh;
|
||||
push @failures, $file if $marker_found;
|
||||
},
|
||||
},
|
||||
File::Spec->curdir()
|
||||
);
|
||||
|
||||
is(
|
||||
@failures, 0,
|
||||
'Files should not contain merge markers' . ( @failures ? ( ' (' . join( ', ', @failures ) . ' )' ) : '' )
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue