View | Details | Raw Unified | Return to bug 40858
Collapse All | Expand All

(-)a/Koha/Devel/Files.pm (-4 / +28 lines)
Lines 132-141 Builds a Git exclude pattern for a given file type based on the context provided Link Here
132
=cut
132
=cut
133
133
134
sub build_git_exclude {
134
sub build_git_exclude {
135
    my ( $self, $filetype ) = @_;
135
    my ( $self, $filetype, $extensions ) = @_;
136
    return $self->{context} && exists $exceptions->{$filetype}->{ $self->{context} }
136
    my $exclude_list = q{};
137
        ? join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype}->{ $self->{context} } } ) )
137
    if ($filetype) {
138
        : q{};
138
        $exclude_list .=
139
            $self->{context} && exists $exceptions->{$filetype}->{ $self->{context} }
140
            ? join( " ", map( "':(exclude)$_'", @{ $exceptions->{$filetype}->{ $self->{context} } } ) )
141
            : q{};
142
    }
143
    if ($extensions) {
144
        $exclude_list .= join( " ", map( "':(exclude)*.$_'", @$extensions ) );
145
    }
146
    return $exclude_list;
139
}
147
}
140
148
141
=head2 ls_perl_files
149
=head2 ls_perl_files
Lines 219-224 sub ls_css_files { Link Here
219
    return @files;
227
    return @files;
220
}
228
}
221
229
230
=head2 ls_all_files
231
232
    my @files = $file_manager->ls_all_files([$extension_list_to_exclude]);
233
234
Lists all files in the repository. Accept a list of extension to exclude.
235
236
=cut
237
238
sub ls_all_files {
239
    my ( $self, $extensions ) = @_;
240
    my $cmd   = sprintf q{git ls-files %s}, $self->build_git_exclude( undef, $extensions );
241
    my @files = qx{$cmd};
242
    chomp for @files;
243
    return @files;
244
}
245
222
=head2 get_filetype
246
=head2 get_filetype
223
247
224
    my $filetype = $file_manager->get_filetype($filename);
248
    my $filetype = $file_manager->get_filetype($filename);
(-)a/t/00-merge-conflict-markers.t (-37 / +17 lines)
Lines 16-60 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
use Test::More;
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 2;
22
use File::Spec;
23
use File::Find;
24
use IO::File;
25
26
my @failures;
27
find(
28
    {
29
        bydepth  => 1,
30
        no_chdir => 1,
31
        wanted   => sub {
32
            my $file = $_;
33
21
34
            return if $file =~ /\.(ico|jpg|gif|ogg|pdf|png|psd|swf|zip|.*\~)$/;
22
use Koha::Devel::Files;
35
            return unless -f $file;
36
23
37
            my @name_parts = File::Spec->splitpath($file);
24
my $dev_files = Koha::Devel::Files->new( { context => 'full' } );
38
            my %dirs       = map { $_ => 1 } File::Spec->splitdir( $name_parts[1] );
25
my @files     = $dev_files->ls_all_files( [qw(ico jpg gif ogg pdf png psd)] );
39
            return if exists $dirs{'.git'};
40
26
41
            my $fh           = IO::File->new( $file, 'r' );
27
plan tests => scalar @files + 1;
42
            my $marker_found = 0;
43
            while ( my $line = <$fh> ) {
44
28
45
                # could check for ^=====, but that's often used in text files
29
for my $file (@files) {
46
                $marker_found++ if $line =~ m|^<<<<<<|;
30
    my $has_conflicts;
47
                $marker_found++ if $line =~ m|^>>>>>>|;
31
    open my $fh, '<', $file or die "Cannot open $file: $!";
48
                last            if $marker_found;
32
    while ( my $line = <$fh> ) {
49
            }
50
            close $fh;
51
            push @failures, $file if $marker_found;
52
        },
53
    },
54
    File::Spec->curdir()
55
);
56
33
57
is(
34
        # Could check for ^=====, but that's often used in text files
58
    @failures, 0,
35
        if ( $line =~ /^<<<<<<<|^>>>>>>>/ ) {
59
    'Files should not contain merge markers' . ( @failures ? ( ' (' . join( ', ', @failures ) . ' )' ) : '' )
36
            $has_conflicts = 1;
60
);
37
        }
38
    }
39
    ok( !$has_conflicts, "$file should not contain merge conflict markers" );
40
    close $fh;
41
}
61
- 

Return to bug 40858