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,10 +132,18 @@ Builds a Git exclude pattern for a given file type based on the context provided
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub build_git_exclude {
|
sub build_git_exclude {
|
||||||
my ( $self, $filetype ) = @_;
|
my ( $self, $filetype, $extensions ) = @_;
|
||||||
return $self->{context} && exists $exceptions->{$filetype}->{ $self->{context} }
|
my $exclude_list = q{};
|
||||||
? join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype}->{ $self->{context} } } ) )
|
if ($filetype) {
|
||||||
: q{};
|
$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
|
=head2 ls_perl_files
|
||||||
|
|
@ -219,6 +227,22 @@ sub ls_css_files {
|
||||||
return @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
|
=head2 get_filetype
|
||||||
|
|
||||||
my $filetype = $file_manager->get_filetype($filename);
|
my $filetype = $file_manager->get_filetype($filename);
|
||||||
|
|
|
||||||
|
|
@ -16,45 +16,26 @@
|
||||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
|
use Test::More;
|
||||||
use Test::NoWarnings;
|
use Test::NoWarnings;
|
||||||
use Test::More tests => 2;
|
|
||||||
use File::Spec;
|
|
||||||
use File::Find;
|
|
||||||
use IO::File;
|
|
||||||
|
|
||||||
my @failures;
|
use Koha::Devel::Files;
|
||||||
find(
|
|
||||||
{
|
|
||||||
bydepth => 1,
|
|
||||||
no_chdir => 1,
|
|
||||||
wanted => sub {
|
|
||||||
my $file = $_;
|
|
||||||
|
|
||||||
return if $file =~ /\.(ico|jpg|gif|ogg|pdf|png|psd|swf|zip|.*\~)$/;
|
my $dev_files = Koha::Devel::Files->new( { context => 'full' } );
|
||||||
return unless -f $file;
|
my @files = $dev_files->ls_all_files( [qw(ico jpg gif ogg pdf png psd)] );
|
||||||
|
|
||||||
my @name_parts = File::Spec->splitpath($file);
|
plan tests => scalar @files + 1;
|
||||||
my %dirs = map { $_ => 1 } File::Spec->splitdir( $name_parts[1] );
|
|
||||||
return if exists $dirs{'.git'};
|
|
||||||
|
|
||||||
my $fh = IO::File->new( $file, 'r' );
|
for my $file (@files) {
|
||||||
my $marker_found = 0;
|
my $has_conflicts;
|
||||||
while ( my $line = <$fh> ) {
|
open my $fh, '<', $file or die "Cannot open $file: $!";
|
||||||
|
while ( my $line = <$fh> ) {
|
||||||
|
|
||||||
# could check for ^=====, but that's often used in text files
|
# Could check for ^=====, but that's often used in text files
|
||||||
$marker_found++ if $line =~ m|^<<<<<<|;
|
if ( $line =~ /^<<<<<<<|^>>>>>>>/ ) {
|
||||||
$marker_found++ if $line =~ m|^>>>>>>|;
|
$has_conflicts = 1;
|
||||||
last if $marker_found;
|
}
|
||||||
}
|
}
|
||||||
close $fh;
|
ok( !$has_conflicts, "$file should not contain merge conflict markers" );
|
||||||
push @failures, $file if $marker_found;
|
close $fh;
|
||||||
},
|
}
|
||||||
},
|
|
||||||
File::Spec->curdir()
|
|
||||||
);
|
|
||||||
|
|
||||||
is(
|
|
||||||
@failures, 0,
|
|
||||||
'Files should not contain merge markers' . ( @failures ? ( ' (' . join( ', ', @failures ) . ' )' ) : '' )
|
|
||||||
);
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue