blib/lib/App/Git/Workflow/Command/BranchConflicts.pm

filter: Statementstmt 96.2% 77 / 80 Branchbran 72.7% 16 / 22 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 87.0% 114 / 131 CC 16 SCAR 20.7
CC
16
Cov
88%
run
15.6
merge_branch_conflicts
2.0
cleanup
2.0
CRAP 7.9
↑ Summary
1 package App::Git::Workflow::Command::BranchConflicts;
2  
3 # Created on: 2015-04-12 06:56:18
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Pod::Usage ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use App::Git::Workflow;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use App::Git::Workflow::Command qw/get_options/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Capture::Tiny qw/capture_stderr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 our $VERSION = 0.6;
19 2 our $workflow = App::Git::Workflow->new;
20 2 our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
21 2 our %option;
22  
23 3 ▶sub run {
Subroutine run: called CC=14 SCAR=27.5
Pod documented
24 3 my ($self) = @_;
25  
26 3 get_options(
27 \%option,
28 'remote|r',
29 'both|a',
30 'merge|m=s',
31 'since|s=s',
32 'ignore|i=s',
33 'quiet|q',
34 );
35  
36 3 ▶ my ($type, @arg) = $option{remote} ? (qw/remote -r/) : $option{both} ? (qw/both -a/) : ();
Branch: 2 branches
BranchTrueFalseTotal
$App::Git::Workflow::Command::BranchConflicts::option{'remote'} ? : 1 2 3
$App::Git::Workflow::Command::BranchConflicts::option{'both'} ? : 0 2 2
37 my @branches
38 = $option{merge}
39 0 ? map {/^\s+(.*)$/; $1} $workflow->git->branch(@arg, '--no-merged', $option{merge})
40 3 ▶ : $workflow->branches($type);
Branch: 1 branch
BranchTrueFalseTotal
$App::Git::Workflow::Command::BranchConflicts::option{'merge'} ? : 0 3 3
41 3 my %conflicts;
42  
43 # check all branches for conflicts with other branches
44 3 ▶ while (@branches > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@branches > 1) 6 3 9
45 6 my $first_branch = shift @branches;
46 6 ▶ next if $option{since} && !$workflow->git->log(qw/-n1 --since/, $option{since}, $first_branch);
Branch: 1 branch
BranchTrueFalseTotal
if $App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $first_branch) 0 6 6
Condition33%1/3
$App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $first_branch)
!ll&&!rl&&r
600
MC/DC0%0/2
$App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $first_branch)
$App::Git::Workflow::Command::BranchConflicts::option{"since"} not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $first_branch)
Truth table33%1/3
A and not(B)
A= $App::Git::Workflow::Command::BranchConflicts::option{"since"}B= not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $first_branch)
ABresult
0X0
100
111
47  
48 6 ▶ print "Checking $first_branch\n" if $option{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $App::Git::Workflow::Command::BranchConflicts::option{"verbose"} 0 6 6
49  
50 6 $self->checkout_branch($first_branch);
51  
52 6 for my $branch (@branches) {
53 12 ▶ next if $option{since} && !$workflow->git->log(qw/-n1 --since/, $option{since}, $branch);
Branch: 1 branch
BranchTrueFalseTotal
if $App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $branch) 0 12 12
Condition33%1/3
$App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $branch)
!ll&&!rl&&r
1200
MC/DC0%0/2
$App::Git::Workflow::Command::BranchConflicts::option{"since"} and not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $branch)
$App::Git::Workflow::Command::BranchConflicts::option{"since"} not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $branch)
Truth table33%1/3
A and not(B)
A= $App::Git::Workflow::Command::BranchConflicts::option{"since"}B= not $App::Git::Workflow::Command::BranchConflicts::workflow->git->log(("-n1", "--since"), $App::Git::Workflow::Command::BranchConflicts::option{"since"}, $branch)
ABresult
0X0
100
111
54 12 ▶ if ( $self->merge_branch_conflicts($branch) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->merge_branch_conflicts($branch)) 2 10 12
55 2 push @{ $conflicts{$first_branch} }, $branch;
56 }
57 }
58  
59 6 $workflow->git->reset('HEAD');
60 6 $workflow->git->clean('-xfd');
61 6 $workflow->git->checkout('.');
62 6 ▶ capture_stderr {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 6 $workflow->git->checkout('-');
64 6 };
65 }
66  
67 3 ▶ if (%conflicts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%conflicts) { } 1 2 3
68 1 print "Conflicting branches:\n";
69 1 for my $branch (sort keys %conflicts) {
70 2 print " $branch\n", map {" $_\n"} @{ $conflicts{$branch} };
71 }
72 }
73 else {
74 2 print "No conflicts.\n";
75 }
76  
77 3 $self->cleanup();
78  
79 3 return;
80 }
81  
82 2 my @checkouts;
83 6 ▶sub checkout_branch {
Subroutine checkout_branch: called CC=1 SCAR=0.0
Pod documented
84 6 my ($self, $branch) = @_;
85  
86 6 my $local = 'branch-conflicts-' . sprintf '%03i', scalar @checkouts;
87 6 ▶ capture_stderr {
Subroutine __ANON__: called CC=1 SCAR=0.0
88 6 $workflow->git->checkout('-b', $local, '--no-track', $branch);
89 6 };
90  
91 6 push @checkouts, $local;
92  
93 6 return $local;
94 }
95  
96 12 ▶sub merge_branch_conflicts {
Subroutine merge_branch_conflicts: called CC=2 SCAR=7.0
Pod documented
97 12 my ($self, $branch) = @_;
98  
99 12 ▶ capture_stderr {
Subroutine __ANON__: called CC=1 SCAR=0.0
100 12 eval { $workflow->git->merge('--no-commit', $branch) };
101 12 };
102 12 my $status = $workflow->git->status;
103 12 eval { $workflow->git->merge('--abort'); };
104  
105 12 ▶ if ($option{ignore}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($App::Git::Workflow::Command::BranchConflicts::option{"ignore"}) 0 12 12
106 0 $status =~ s/both (?:added|modified): \s+ $option{ignore}//;
107 }
108  
109 12 return $status =~ /both (?:added|modified)/;
110 }
111  
112 3 ▶sub cleanup {
Subroutine cleanup: called CC=2 SCAR=6.9
Pod documented
113  
114 3 ▶ while ( my $branch = shift @checkouts) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $branch = shift @checkouts) 6 3 9
115 6 $workflow->git->branch('-D', $branch);
116 }
117  
118 3 return;
119 }
120 2 1;
121  
122 __DATA__
↑ Summary