From abef385a13fe0bd20244e842f40e3a2bb119de8f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 23 Sep 2025 10:22:15 +0200 Subject: [PATCH] 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 Signed-off-by: Paul Derscheid --- Koha/Devel/Files.pm | 32 ++++++++++++++++++--- t/00-merge-conflict-markers.t | 53 +++++++++++------------------------ 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/Koha/Devel/Files.pm b/Koha/Devel/Files.pm index 0fc5b2ec258..8ca8cc5cec9 100644 --- a/Koha/Devel/Files.pm +++ b/Koha/Devel/Files.pm @@ -132,10 +132,18 @@ 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} } - ? join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype}->{ $self->{context} } } ) ) - : q{}; + 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); diff --git a/t/00-merge-conflict-markers.t b/t/00-merge-conflict-markers.t index dbfecbc04df..ad02e706477 100755 --- a/t/00-merge-conflict-markers.t +++ b/t/00-merge-conflict-markers.t @@ -16,45 +16,26 @@ # along with Koha; if not, see . 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 = $_; - return if $file =~ /\.(ico|jpg|gif|ogg|pdf|png|psd|swf|zip|.*\~)$/; - return unless -f $file; +use Koha::Devel::Files; - my @name_parts = File::Spec->splitpath($file); - my %dirs = map { $_ => 1 } File::Spec->splitdir( $name_parts[1] ); - return if exists $dirs{'.git'}; +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 $fh = IO::File->new( $file, 'r' ); - my $marker_found = 0; - while ( my $line = <$fh> ) { +plan tests => scalar @files + 1; - # 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; - } - close $fh; - push @failures, $file if $marker_found; - }, - }, - File::Spec->curdir() -); +for my $file (@files) { + my $has_conflicts; + open my $fh, '<', $file or die "Cannot open $file: $!"; + while ( my $line = <$fh> ) { -is( - @failures, 0, - 'Files should not contain merge markers' . ( @failures ? ( ' (' . join( ', ', @failures ) . ' )' ) : '' ) -); + # 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; +} -- 2.39.5