Plugin/Git/CheckFor/MergeConflicts.pm

filter: Statementstmt 48.0% 25 / 52 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 2 totaltotal 36.9% 31 / 84 CC 12 SCAR 45.0
CC
12
Cov
37%
before_release
156.0
__ANON__
2.0
mvp_multivalue_args
2.0
CRAP 89.7
↑ Summary Plugin/Git/CheckFor/CorrectBranch.pm »
1 #
2 # This file is part of Dist-Zilla-PluginBundle-Git-CheckFor
3 #
4 # This software is Copyright (c) 2026 by Chris Weyl.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts;
11 1 our $AUTHORITY = 'cpan:RSRCHBOY';
12 1 $Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts::VERSION = '0.015';
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Check your repo for merge-conflicted files
17 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use autodie qw(:io);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use List::Util 1.33 qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 with
23 'Dist::Zilla::Role::BeforeRelease',
24 'Dist::Zilla::Role::Git::Repo::More',
25 #-excludes => [ qw { _build_version_regexp _build_first_version } ],
26 ;
27  
28 has merge_conflict_patterns => (
29 is => 'ro',
30 isa => 'ArrayRef[RegexpRef]',
31 lazy => 1,
32 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 my $self = shift;
34 0 my $repo = $self->_repo;
35 0 my ($branch) = $repo->branch;
36 return [
37 0 qr/^=======/,
38 qr/^<<<<<<< Updated upstream/,
39 qr/^>>>>>>> Stashed changes/,
40 qr/^<<<<<<< HEAD/,
41 qr/^>>>>>>> \Q$branch\E/,
42 ];
43 },
44 1 );
45  
46 1 has ignore => (
47 is => 'ro',
48 isa => 'ArrayRef[Str]',
49 predicate => 'has_ignore',
50 );
51  
52 0 ▶sub mvp_multivalue_args { qw( ignore ) }
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod undocumented
53  
54 0 ▶sub before_release {
Subroutine before_release: not called CC=12 SCAR=50.5
Pod undocumented
55 0 my $self = shift;
56  
57 0 my %error_files;
58 FILE:
59 0 foreach my $file ( @{ $self->zilla->files } ) {
60 next FILE
61 0 ▶ if $file->can('encoding') and $file->encoding eq 'bytes';
Branch: 1 branch
BranchTrueFalseTotal
if $file->can("encoding") and $file->encoding eq "bytes" 0 0 0
Condition0%0/3
$file->can("encoding") and $file->encoding eq "bytes"
!ll&&!rl&&r
000
MC/DC0%0/2
$file->can("encoding") and $file->encoding eq "bytes"
$file->can("encoding") $file->encoding eq "bytes"
Truth table0%0/3
A and B
A= $file->can("encoding")B= $file->encoding eq "bytes"
ABresult
0X0
100
111
62  
63 next FILE
64 if $self->has_ignore
65 0 ▶ and any { $file->name eq $_ } @{ $self->ignore };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_ignore and &any(sub { $file->name eq $_; } , @{$self->ignore;}) 0 0 0
Condition0%0/3
$self->has_ignore and &any(sub { $file->name eq $_; } , @{$self->ignore;})
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_ignore and &any(sub { $file->name eq $_; } , @{$self->ignore;})
$self->has_ignore &any(sub { $file->name eq $_; } , @{$self->ignore;})
Truth table0%0/3
A and B
A= $self->has_ignoreB= &any(sub { $file->name eq $_; } , @{$self->ignore;})
ABresult
0X0
100
111
66  
67 0 my $text = $file->content;
68 0 foreach my $re ( @{ $self->merge_conflict_patterns } ) {
69 0 foreach my $line (split $/, $text) {
70 0 ▶ if ( $line =~ m/($re)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /($re)/) 0 0 0
71 0 push @{ $error_files{ $file->name } }, "matched $re at line $.";
72 }
73 }
74 }
75 }
76  
77 0 ▶ if (%error_files) {
Branch: 1 branch
BranchTrueFalseTotal
if (%error_files) 0 0 0
78 0 my $error_msg = "Aborting release; found merge conflict markers:\n";
79 0 ▶ while ( my ($filename, $error) = each %error_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %error_files) 0 0 0
80 0 $error_msg .= "$filename $_\n" for @$error;
81 }
82 0 $self->log_fatal( $error_msg );
83 }
84  
85 0 $self->log('No merge conflict markers found; OK to release');
86 0 return;
87 }
88  
89 1 __PACKAGE__->meta->make_immutable;
90  
91 1 1;
92  
93 __END__
↑ Summary Plugin/Git/CheckFor/CorrectBranch.pm »