line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Git::Workflow::Command::Take; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2015-06-05 11:38:28 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
67541
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
11
|
1
|
|
|
1
|
|
521
|
use Pod::Usage (); |
|
1
|
|
|
|
|
50426
|
|
|
1
|
|
|
|
|
29
|
|
12
|
1
|
|
|
1
|
|
623
|
use Data::Dumper qw/Dumper/; |
|
1
|
|
|
|
|
6391
|
|
|
1
|
|
|
|
|
69
|
|
13
|
1
|
|
|
1
|
|
551
|
use English qw/ -no_match_vars /; |
|
1
|
|
|
|
|
3445
|
|
|
1
|
|
|
|
|
5
|
|
14
|
1
|
|
|
1
|
|
821
|
use App::Git::Workflow; |
|
1
|
|
|
|
|
47994
|
|
|
1
|
|
|
|
|
49
|
|
15
|
1
|
|
|
1
|
|
475
|
use App::Git::Workflow::Command qw/get_options/; |
|
1
|
|
|
|
|
12132
|
|
|
1
|
|
|
|
|
62
|
|
16
|
1
|
|
|
1
|
|
803
|
use Path::Tiny; |
|
1
|
|
|
|
|
10830
|
|
|
1
|
|
|
|
|
56
|
|
17
|
1
|
|
|
1
|
|
509
|
use File::Copy qw/copy/; |
|
1
|
|
|
|
|
2328
|
|
|
1
|
|
|
|
|
573
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.6; |
20
|
|
|
|
|
|
|
our $workflow = App::Git::Workflow->new; |
21
|
|
|
|
|
|
|
our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs; |
22
|
|
|
|
|
|
|
our %option; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub run { |
25
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
get_options( |
28
|
|
|
|
|
|
|
\%option, |
29
|
|
|
|
|
|
|
'quiet|q', |
30
|
|
|
|
|
|
|
'ours|mine', |
31
|
|
|
|
|
|
|
'theirs', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my @conflicts = ( |
35
|
0
|
|
|
|
|
|
map { /^ \s+ both \s modified: \s+(.*)$/xms; $1 } |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
grep { /^ \s+ both \s modified: \s+/xms } |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$workflow->git->status() |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (!@ARGV) { |
41
|
0
|
|
|
|
|
|
@ARGV = ('./'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
CONFLICT: |
45
|
0
|
|
|
|
|
|
for my $conflict (@conflicts) { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
PATH: |
48
|
0
|
|
|
|
|
|
for my $path (@ARGV) { |
49
|
0
|
|
|
|
|
|
$path =~ s{^[.]/}{}; |
50
|
0
|
0
|
|
|
|
|
next PATH unless $conflict =~ /^\Q$path\E/; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
resolve($conflict); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
next CONFLICT; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub resolve { |
62
|
0
|
|
|
0
|
1
|
|
my ($file) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
print "Resolving $file\n"; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %states = ( |
67
|
|
|
|
|
|
|
ours => qr/^<<<<<<</, |
68
|
|
|
|
|
|
|
theirs => qr/^=======/, |
69
|
|
|
|
|
|
|
keep => qr/^>>>>>>>/, |
70
|
|
|
|
|
|
|
); |
71
|
0
|
|
|
|
|
|
my $state = 'keep'; |
72
|
0
|
0
|
|
|
|
|
my $side = $option{theirs} ? 'theirs' : 'ours'; |
73
|
0
|
|
|
|
|
|
my $read = path($file)->openr; |
74
|
0
|
|
|
|
|
|
my $tmp = path($file . '.tmp'); |
75
|
0
|
|
|
|
|
|
my $write = $tmp->openw; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
LINE: |
78
|
0
|
|
|
|
|
|
while (my $line = <$read>) { |
79
|
0
|
|
|
|
|
|
for my $check (keys %states) { |
80
|
0
|
0
|
|
|
|
|
if ( $line =~ /$states{$check}/ ) { |
81
|
0
|
|
|
|
|
|
$state = $check; |
82
|
0
|
|
|
|
|
|
next LINE; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
|
print {$write} $line if $state eq 'keep' || $state eq $side; |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
close $write; |
90
|
0
|
|
|
|
|
|
unlink $file; |
91
|
0
|
|
|
|
|
|
copy $tmp, $file; |
92
|
0
|
|
|
|
|
|
unlink $tmp; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__DATA__ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
App::Git::Workflow::Command::Take - Resolve merge conflicts by only taking one side of each conflicted section |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This documentation refers to git-take-mine version 0.6 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
git-take-mine [option] [path_or_file] |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
OPTIONS: |
114
|
|
|
|
|
|
|
-q --quiet Suppress notifying of files changed |
115
|
|
|
|
|
|
|
--ours Take choanges from current branch throwing away other branches changes |
116
|
|
|
|
|
|
|
--theirs Take changes from merging branch throwing away current branches changes |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
-v --verbose Show more detailed option |
119
|
|
|
|
|
|
|
--VERSION Prints the version information |
120
|
|
|
|
|
|
|
--help Prints this help information |
121
|
|
|
|
|
|
|
--man Prints the full documentation for git-take-mine |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
C<git take> provides a way of quickly resolving conflicts by taking only one |
126
|
|
|
|
|
|
|
side of the conflict. It does this differently to C<git checkout --ours> / |
127
|
|
|
|
|
|
|
C<git checkout --theirs> as it only takes the conflicted part not the whole |
128
|
|
|
|
|
|
|
of one side of the merge. Where this can come in handy is for merging things |
129
|
|
|
|
|
|
|
with version number (eg pom.xml) where only the version number conflicts and |
130
|
|
|
|
|
|
|
there may be other changes in the file that should be taken. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 C<run ()> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Finds the conflicted files to resolve |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 C<resolve ($file)> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Resolves conflicts in C<$file> in favor of C<--ours> or C<--theirs>. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
There are no known bugs in this module. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Patches are welcome. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (c) 2015 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
165
|
|
|
|
|
|
|
All rights reserved. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
168
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
169
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
170
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
171
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |