| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::GitGot::Command; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENEHACK'; |
|
3
|
|
|
|
|
|
|
$App::GitGot::Command::VERSION = '1.339'; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: Base class for App::GitGot commands |
|
5
|
20
|
|
|
20
|
|
13867
|
use 5.014; |
|
|
20
|
|
|
|
|
78
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
20
|
|
|
19
|
|
234
|
use App::Cmd::Setup -command; |
|
|
19
|
|
|
|
|
70
|
|
|
|
19
|
|
|
|
|
117
|
|
|
8
|
19
|
|
|
16
|
|
3133
|
use Cwd; |
|
|
16
|
|
|
|
|
49
|
|
|
|
16
|
|
|
|
|
1055
|
|
|
9
|
16
|
|
|
15
|
|
6881
|
use File::HomeDir::Tiny (); |
|
|
15
|
|
|
|
|
4395
|
|
|
|
15
|
|
|
|
|
362
|
|
|
10
|
15
|
|
|
15
|
|
108
|
use List::Util qw/ max first /; |
|
|
15
|
|
|
|
|
34
|
|
|
|
15
|
|
|
|
|
1673
|
|
|
11
|
15
|
|
|
15
|
|
122
|
use Path::Tiny; |
|
|
15
|
|
|
|
|
32
|
|
|
|
15
|
|
|
|
|
649
|
|
|
12
|
15
|
|
|
15
|
|
86
|
use Try::Tiny; |
|
|
15
|
|
|
|
|
33
|
|
|
|
15
|
|
|
|
|
827
|
|
|
13
|
15
|
|
|
15
|
|
8452
|
use Types::Standard -types; |
|
|
15
|
|
|
|
|
1152463
|
|
|
|
15
|
|
|
|
|
177
|
|
|
14
|
15
|
|
|
15
|
|
73147
|
use YAML qw/ DumpFile LoadFile /; |
|
|
15
|
|
|
|
|
43
|
|
|
|
15
|
|
|
|
|
1043
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
15
|
|
|
15
|
|
7921
|
use App::GitGot::Repo::Git; |
|
|
15
|
|
|
|
|
64
|
|
|
|
15
|
|
|
|
|
665
|
|
|
17
|
15
|
|
|
15
|
|
9102
|
use App::GitGot::Repositories; |
|
|
15
|
|
|
|
|
71
|
|
|
|
15
|
|
|
|
|
760
|
|
|
18
|
15
|
|
|
15
|
|
141
|
use App::GitGot::Types -all; |
|
|
15
|
|
|
|
|
38
|
|
|
|
15
|
|
|
|
|
143
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
15
|
|
|
15
|
|
32558
|
use Moo; |
|
|
15
|
|
|
|
|
39
|
|
|
|
15
|
|
|
|
|
90
|
|
|
21
|
15
|
|
|
15
|
|
7698
|
use MooX::HandlesVia; |
|
|
15
|
|
|
|
|
50
|
|
|
|
15
|
|
|
|
|
125
|
|
|
22
|
15
|
|
|
15
|
|
1866
|
use namespace::autoclean; |
|
|
15
|
|
|
|
|
41
|
|
|
|
15
|
|
|
|
|
140
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub opt_spec { |
|
25
|
42
|
|
|
42
|
1
|
358397
|
my( $class , $app ) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return ( |
|
28
|
42
|
|
|
|
|
1871
|
[ 'all|a' => 'use all available repositories' ] , |
|
29
|
|
|
|
|
|
|
[ 'by_path|p' => 'if set, output will be sorted by repo path (default: sort by repo name)' ] , |
|
30
|
|
|
|
|
|
|
[ 'color_scheme|c=s' => 'name of color scheme to use' => { default => 'dark' } ] , |
|
31
|
|
|
|
|
|
|
[ 'configfile|f=s' => 'path to config file' => { default => path( File::HomeDir::Tiny::home() , '.gitgot') , required => 1 } ] , |
|
32
|
|
|
|
|
|
|
[ 'no_color|C' => 'do not use colored output' => { default => 0 } ] , |
|
33
|
|
|
|
|
|
|
[ 'quiet|q' => 'keep it down' ] , |
|
34
|
|
|
|
|
|
|
[ 'skip_tags|T=s@' => 'select repositories not tagged with these words' ] , |
|
35
|
|
|
|
|
|
|
[ 'tags|t=s@' => 'select repositories tagged with these words' ] , |
|
36
|
|
|
|
|
|
|
[ 'verbose|v' => 'bring th\' noise'] , |
|
37
|
|
|
|
|
|
|
$class->options($app) |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
8
|
0
|
|
sub options {} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has active_repo_list => ( |
|
44
|
|
|
|
|
|
|
is => 'lazy', |
|
45
|
|
|
|
|
|
|
isa => ArrayRef[GotRepo] , |
|
46
|
|
|
|
|
|
|
handles_via => 'Array' , |
|
47
|
|
|
|
|
|
|
handles => { |
|
48
|
|
|
|
|
|
|
active_repos => 'elements' , |
|
49
|
|
|
|
|
|
|
} , |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _build_active_repo_list { |
|
53
|
21
|
|
|
21
|
|
896
|
my ( $self ) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $self->full_repo_list |
|
56
|
21
|
100
|
66
|
|
|
526
|
if $self->all or ! $self->tags and ! $self->skip_tags and ! @{ $self->args }; |
|
|
|
|
100
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
4
|
|
|
|
|
53
|
my $list = _expand_arg_list( $self->args ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
11
|
my @repos; |
|
61
|
4
|
|
|
|
|
128
|
REPO: foreach my $repo ( $self->all_repos ) { |
|
62
|
12
|
100
|
|
|
|
600
|
if ( grep { $_ eq $repo->number or $_ eq $repo->name } @$list ) { |
|
|
12
|
100
|
|
|
|
139
|
|
|
63
|
4
|
|
|
|
|
12
|
push @repos, $repo; |
|
64
|
4
|
|
|
|
|
17
|
next REPO; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
8
|
50
|
|
|
|
156
|
if ( $self->skip_tags ) { |
|
68
|
0
|
|
|
|
|
0
|
foreach my $tag ( @{ $self->skip_tags } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
69
|
0
|
0
|
|
|
|
0
|
next REPO if grep { $repo->tags =~ /\b$_\b/ } $tag; |
|
|
0
|
|
|
|
|
0
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
8
|
50
|
|
|
|
365
|
if ( $self->tags ) { |
|
74
|
0
|
|
|
|
|
0
|
foreach my $tag ( @{ $self->tags } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
75
|
0
|
0
|
|
|
|
0
|
if ( grep { $repo->tags =~ /\b$_\b/ } $tag ) { |
|
|
0
|
|
|
|
|
0
|
|
|
76
|
0
|
|
|
|
|
0
|
push @repos, $repo; |
|
77
|
0
|
|
|
|
|
0
|
next REPO; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
8
|
50
|
33
|
|
|
361
|
push @repos, $repo unless $self->tags or @$list; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
155
|
return \@repos; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has args => ( |
|
88
|
|
|
|
|
|
|
is => 'rwp' , |
|
89
|
|
|
|
|
|
|
isa => ArrayRef , |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
has full_repo_list => ( |
|
93
|
|
|
|
|
|
|
is => 'lazy', |
|
94
|
|
|
|
|
|
|
isa => ArrayRef[GotRepo] , |
|
95
|
|
|
|
|
|
|
writer => 'set_full_repo_list' , |
|
96
|
|
|
|
|
|
|
handles_via => 'Array' , |
|
97
|
|
|
|
|
|
|
handles => { |
|
98
|
|
|
|
|
|
|
add_repo => 'push' , |
|
99
|
|
|
|
|
|
|
all_repos => 'elements' , |
|
100
|
|
|
|
|
|
|
} , |
|
101
|
|
|
|
|
|
|
); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _build_full_repo_list { |
|
104
|
37
|
|
|
37
|
|
1299
|
my $self = shift; |
|
105
|
|
|
|
|
|
|
|
|
106
|
37
|
|
|
|
|
929
|
my $config = _read_config( $self->configfile ); |
|
107
|
|
|
|
|
|
|
|
|
108
|
37
|
|
|
|
|
127
|
my $repo_count = 1; |
|
109
|
|
|
|
|
|
|
|
|
110
|
37
|
50
|
|
|
|
1355
|
my $sort_key = $self->by_path ? 'path' : 'name'; |
|
111
|
|
|
|
|
|
|
|
|
112
|
37
|
|
|
|
|
1467
|
my @parsed_config; |
|
113
|
|
|
|
|
|
|
|
|
114
|
37
|
|
|
|
|
306
|
foreach my $entry ( sort { $a->{$sort_key} cmp $b->{$sort_key} } @$config ) { |
|
|
90
|
|
|
|
|
305
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# a completely empty entry is okay (this will happen when there's no |
|
117
|
|
|
|
|
|
|
# config at all...) |
|
118
|
92
|
100
|
|
|
|
5352
|
keys %$entry or next; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
### FIXME unnecessarily git specific |
|
121
|
|
|
|
|
|
|
push @parsed_config , App::GitGot::Repo::Git->new({ |
|
122
|
|
|
|
|
|
|
label => ( $self->by_path ) ? $entry->{path} : $entry->{name} , |
|
123
|
84
|
50
|
|
|
|
1774
|
entry => $entry , |
|
124
|
|
|
|
|
|
|
count => $repo_count++ , |
|
125
|
|
|
|
|
|
|
}); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
37
|
|
|
|
|
3407
|
return \@parsed_config; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
has opt => ( |
|
132
|
|
|
|
|
|
|
is => 'rwp' , |
|
133
|
|
|
|
|
|
|
isa => Object , |
|
134
|
|
|
|
|
|
|
handles => [ qw/ |
|
135
|
|
|
|
|
|
|
all |
|
136
|
|
|
|
|
|
|
by_path |
|
137
|
|
|
|
|
|
|
color_scheme |
|
138
|
|
|
|
|
|
|
configfile |
|
139
|
|
|
|
|
|
|
no_color |
|
140
|
|
|
|
|
|
|
quiet |
|
141
|
|
|
|
|
|
|
skip_tags |
|
142
|
|
|
|
|
|
|
tags |
|
143
|
|
|
|
|
|
|
verbose |
|
144
|
|
|
|
|
|
|
/ ] |
|
145
|
|
|
|
|
|
|
); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
has outputter => ( |
|
148
|
|
|
|
|
|
|
is => 'lazy' , |
|
149
|
|
|
|
|
|
|
isa => GotOutputter , |
|
150
|
|
|
|
|
|
|
handles => [ |
|
151
|
|
|
|
|
|
|
'error' , |
|
152
|
|
|
|
|
|
|
'warning' , |
|
153
|
|
|
|
|
|
|
'major_change' , |
|
154
|
|
|
|
|
|
|
'minor_change' , |
|
155
|
|
|
|
|
|
|
] , |
|
156
|
|
|
|
|
|
|
); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub _build_outputter { |
|
159
|
7
|
|
|
7
|
|
730
|
my $self = shift; |
|
160
|
|
|
|
|
|
|
|
|
161
|
7
|
|
|
|
|
162
|
my $scheme = $self->color_scheme; |
|
162
|
|
|
|
|
|
|
|
|
163
|
7
|
50
|
|
|
|
306
|
if ( $scheme =~ /^\+/ ) { |
|
164
|
0
|
|
|
|
|
0
|
$scheme =~ s/^\+//; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
else { |
|
167
|
7
|
|
|
|
|
31
|
$scheme = "App::GitGot::Outputter::$scheme" |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
try { |
|
171
|
7
|
|
|
7
|
|
1266
|
eval "use $scheme"; |
|
172
|
7
|
50
|
|
|
|
105
|
die $@ if $@; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
catch { |
|
175
|
0
|
|
|
0
|
|
0
|
say "Failed to load color scheme '$scheme'.\nExitting now.\n"; |
|
176
|
0
|
|
|
|
|
0
|
exit(5); |
|
177
|
7
|
|
|
|
|
143
|
}; |
|
178
|
|
|
|
|
|
|
|
|
179
|
7
|
|
|
|
|
338
|
return $scheme->new({ no_color => $self->no_color }); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub execute { |
|
183
|
42
|
|
|
42
|
1
|
201086
|
my( $self , $opt , $args ) = @_; |
|
184
|
42
|
|
|
|
|
1189
|
$self->_set_args( $args ); |
|
185
|
42
|
|
|
|
|
2917
|
$self->_set_opt( $opt ); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# set up colored output if we page thru less |
|
188
|
|
|
|
|
|
|
# also exit pager immediately if <1 page of output |
|
189
|
42
|
|
|
|
|
1774
|
$ENV{LESS} = 'RFX'; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# don't catch any errors here; if this fails we just output stuff like |
|
192
|
|
|
|
|
|
|
# normal and nobody is the wiser. |
|
193
|
42
|
100
|
|
15
|
|
330
|
eval 'use IO::Page' if $self->_use_io_page; |
|
|
15
|
|
|
6
|
|
7804
|
|
|
|
15
|
|
|
1
|
|
4555
|
|
|
|
15
|
|
|
|
|
394
|
|
|
|
6
|
|
|
|
|
68
|
|
|
|
6
|
|
|
|
|
18
|
|
|
|
6
|
|
|
|
|
126
|
|
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
42
|
|
|
|
|
342
|
$self->_execute($opt,$args); |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub local_repo { |
|
200
|
12
|
|
|
12
|
1
|
26
|
my $self = shift; |
|
201
|
|
|
|
|
|
|
|
|
202
|
12
|
|
|
|
|
168
|
my $dir = $self->_find_repo_root( getcwd() ); |
|
203
|
|
|
|
|
|
|
|
|
204
|
11
|
|
|
11
|
|
354
|
return first { $_->path eq $dir->absolute } $self->all_repos; |
|
|
11
|
|
|
|
|
788
|
|
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub max_length_of_an_active_repo_label { |
|
209
|
18
|
|
|
18
|
1
|
47
|
my( $self ) = @_; |
|
210
|
|
|
|
|
|
|
|
|
211
|
18
|
50
|
|
|
|
432
|
my $sort_key = $self->by_path ? 'path' : 'name'; |
|
212
|
|
|
|
|
|
|
|
|
213
|
18
|
|
|
|
|
971
|
return max ( map { length $_->$sort_key } $self->active_repos); |
|
|
72
|
|
|
|
|
2180
|
|
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub prompt_yn { |
|
218
|
0
|
|
|
0
|
1
|
0
|
my( $self , $message ) = @_; |
|
219
|
0
|
|
|
|
|
0
|
printf '%s [y/N]: ' , $message; |
|
220
|
0
|
|
|
|
|
0
|
chomp( my $response = ); |
|
221
|
0
|
|
|
|
|
0
|
return lc($response) eq 'y'; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub search_repos { |
|
226
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
0
|
return App::GitGot::Repositories->new( |
|
229
|
|
|
|
|
|
|
repos => [ $self->all_repos ] |
|
230
|
|
|
|
|
|
|
); |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub write_config { |
|
235
|
14
|
|
|
14
|
1
|
63
|
my ($self) = @_; |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
DumpFile( |
|
238
|
|
|
|
|
|
|
$self->configfile, |
|
239
|
|
|
|
|
|
|
[ |
|
240
|
6
|
|
|
|
|
52
|
sort { $a->{name} cmp $b->{name} } |
|
241
|
14
|
|
|
|
|
490
|
map { $_->in_writable_format } $self->all_repos |
|
|
19
|
|
|
|
|
1712
|
|
|
242
|
|
|
|
|
|
|
] , |
|
243
|
|
|
|
|
|
|
); |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub _expand_arg_list { |
|
247
|
4
|
|
|
4
|
|
18
|
my $args = shift; |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
## no critic |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
return [ |
|
252
|
|
|
|
|
|
|
map { |
|
253
|
4
|
|
|
|
|
13
|
s!/$!!; |
|
|
4
|
|
|
|
|
18
|
|
|
254
|
4
|
50
|
|
|
|
22
|
if (/^(\d+)-(\d+)?$/) { ( $1 .. $2 ) } |
|
|
0
|
|
|
|
|
0
|
|
|
255
|
4
|
|
|
|
|
23
|
else { ($_) } |
|
256
|
|
|
|
|
|
|
} @$args |
|
257
|
|
|
|
|
|
|
]; |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
## use critic |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub _fetch { |
|
263
|
1
|
|
|
1
|
|
328
|
my( $self , @repos ) = @_; |
|
264
|
|
|
|
|
|
|
|
|
265
|
1
|
|
|
|
|
10
|
my $max_len = $self->max_length_of_an_active_repo_label; |
|
266
|
|
|
|
|
|
|
|
|
267
|
1
|
|
|
|
|
5
|
REPO: for my $repo ( @repos ) { |
|
268
|
4
|
100
|
|
|
|
182
|
next REPO unless $repo->repo; |
|
269
|
|
|
|
|
|
|
|
|
270
|
2
|
|
|
|
|
8
|
my $name = $repo->name; |
|
271
|
|
|
|
|
|
|
|
|
272
|
2
|
|
|
|
|
44
|
my $msg = sprintf "%3d) %-${max_len}s : ", $repo->number, $repo->label; |
|
273
|
|
|
|
|
|
|
|
|
274
|
2
|
|
|
|
|
6
|
my ( $status, $fxn ); |
|
275
|
|
|
|
|
|
|
|
|
276
|
2
|
|
|
|
|
9
|
my $repo_type = $repo->type; |
|
277
|
|
|
|
|
|
|
|
|
278
|
2
|
50
|
|
|
|
8
|
if ( $repo_type eq 'git' ) { $fxn = '_git_fetch' } |
|
|
2
|
|
|
|
|
5
|
|
|
279
|
|
|
|
|
|
|
### FIXME elsif( $repo_type eq 'svn' ) { $fxn = 'svn_update' } |
|
280
|
0
|
|
|
|
|
0
|
else { $status = $self->error("ERROR: repo type '$_' not supported") } |
|
281
|
|
|
|
|
|
|
|
|
282
|
2
|
50
|
|
|
|
19
|
$status = $self->$fxn($repo) if ($fxn); |
|
283
|
|
|
|
|
|
|
|
|
284
|
2
|
50
|
33
|
|
|
93
|
next REPO if $self->quiet and !$status; |
|
285
|
|
|
|
|
|
|
|
|
286
|
2
|
|
|
|
|
100
|
say "$msg$status"; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub _find_repo_root { |
|
291
|
12
|
|
|
12
|
|
40
|
my( $self , $path ) = @_; |
|
292
|
|
|
|
|
|
|
|
|
293
|
12
|
|
|
|
|
42
|
my $dir = path( $path ); |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# find repo root |
|
296
|
12
|
100
|
|
|
|
401
|
while ( ! grep { -d and $_->basename eq '.git' } $dir->children ) { |
|
|
71
|
|
|
|
|
6015
|
|
|
297
|
3
|
100
|
|
|
|
153
|
die "$path doesn't seem to be in a git directory\n" if $dir eq $dir->parent; |
|
298
|
2
|
|
|
|
|
151
|
$dir = $dir->parent; |
|
299
|
|
|
|
|
|
|
} |
|
300
|
|
|
|
|
|
|
|
|
301
|
11
|
|
|
|
|
259
|
return $dir |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
sub _git_clone_or_callback { |
|
305
|
6
|
50
|
|
6
|
|
31
|
my( $self , $entry , $callback ) = @_ |
|
306
|
|
|
|
|
|
|
or die "Need entry and callback"; |
|
307
|
|
|
|
|
|
|
|
|
308
|
6
|
|
|
|
|
33
|
my $msg = ''; |
|
309
|
|
|
|
|
|
|
|
|
310
|
6
|
|
|
|
|
38
|
my $path = $entry->path; |
|
311
|
|
|
|
|
|
|
|
|
312
|
6
|
100
|
|
|
|
344
|
if ( !-d $path ) { |
|
|
|
50
|
|
|
|
|
|
|
313
|
3
|
|
|
|
|
29
|
path($path)->mkpath; |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
try { |
|
316
|
3
|
|
|
3
|
|
302
|
$entry->clone( $entry->repo , './' ); |
|
317
|
3
|
|
|
|
|
93
|
$msg .= $self->major_change('Checked out'); |
|
318
|
|
|
|
|
|
|
} |
|
319
|
3
|
|
|
0
|
|
1303
|
catch { $msg .= $self->error('ERROR') . "\n$_" }; |
|
|
0
|
|
|
|
|
0
|
|
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
elsif ( -d "$path/.git" ) { |
|
322
|
|
|
|
|
|
|
try { |
|
323
|
3
|
|
|
3
|
|
232
|
$msg .= $callback->($msg , $entry); |
|
324
|
|
|
|
|
|
|
} |
|
325
|
3
|
|
|
0
|
|
67
|
catch { $msg .= $self->error('ERROR') . "\n$_" }; |
|
|
0
|
|
|
|
|
0
|
|
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
|
|
328
|
6
|
|
|
|
|
160
|
return $msg; |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
} |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
sub _git_fetch { |
|
333
|
2
|
50
|
|
2
|
|
10
|
my ( $self, $entry ) = @_ |
|
334
|
|
|
|
|
|
|
or die "Need entry"; |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
$self->_git_clone_or_callback( $entry , |
|
337
|
|
|
|
|
|
|
sub { |
|
338
|
1
|
|
|
1
|
|
4
|
my( $msg , $entry ) = @_; |
|
339
|
|
|
|
|
|
|
|
|
340
|
1
|
|
|
|
|
47
|
my @o = $entry->fetch; |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
# "git fetch" doesn't output anything to STDOUT only STDERR |
|
343
|
1
|
|
|
|
|
3
|
my @err = @{ $entry->_wrapper->ERR }; |
|
|
1
|
|
|
|
|
55
|
|
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
# If something was updated then STDERR should contain something |
|
346
|
|
|
|
|
|
|
# similar to: |
|
347
|
|
|
|
|
|
|
# |
|
348
|
|
|
|
|
|
|
# From git://example.com/link-to-repo |
|
349
|
|
|
|
|
|
|
# SHA1___..SHA1___ main -> origin/main |
|
350
|
|
|
|
|
|
|
# |
|
351
|
|
|
|
|
|
|
# So search for /^From / in STDERR to see if anything was outputed |
|
352
|
1
|
50
|
|
|
|
8
|
if ( grep { /^From / } @err ) { |
|
|
0
|
50
|
|
|
|
0
|
|
|
353
|
0
|
|
|
|
|
0
|
$msg .= $self->major_change('Updated'); |
|
354
|
0
|
0
|
|
|
|
0
|
$msg .= "\n" . join("\n",@err) unless $self->quiet; |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
elsif ( scalar @err == 0) { |
|
357
|
|
|
|
|
|
|
# No messages to STDERR means repo was already updated |
|
358
|
1
|
50
|
|
|
|
43
|
$msg .= $self->minor_change('Up to date') unless $self->quiet; |
|
359
|
|
|
|
|
|
|
} |
|
360
|
|
|
|
|
|
|
else { |
|
361
|
|
|
|
|
|
|
# Something else occured (possibly a warning) |
|
362
|
|
|
|
|
|
|
# Print STDERR and move on |
|
363
|
0
|
|
|
|
|
0
|
$msg .= $self->warning('Problem during fetch'); |
|
364
|
0
|
0
|
|
|
|
0
|
$msg .= "\n" . join("\n",@err) unless $self->quiet; |
|
365
|
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
|
|
367
|
1
|
|
|
|
|
7
|
return $msg; |
|
368
|
|
|
|
|
|
|
} |
|
369
|
2
|
|
|
|
|
32
|
); |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub _git_status { |
|
373
|
6
|
50
|
|
6
|
|
22
|
my ( $self, $entry ) = @_ |
|
374
|
|
|
|
|
|
|
or die "Need entry"; |
|
375
|
|
|
|
|
|
|
|
|
376
|
6
|
|
|
|
|
28
|
my( $msg , $verbose_msg ) = $self->_run_git_status( $entry ); |
|
377
|
|
|
|
|
|
|
|
|
378
|
6
|
50
|
|
|
|
24
|
$msg .= $self->_run_git_cherry( $entry ) |
|
379
|
|
|
|
|
|
|
if $entry->current_remote_branch; |
|
380
|
6
|
100
|
66
|
|
|
41
|
if ($self->opt->show_branch and defined $entry->current_branch) { |
|
381
|
2
|
|
|
|
|
9
|
$msg .= '[' . $entry->current_branch . ']'; |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
|
|
384
|
6
|
100
|
|
|
|
142
|
return ( $self->verbose ) ? "$msg$verbose_msg" : $msg; |
|
385
|
|
|
|
|
|
|
} |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub _git_update { |
|
388
|
2
|
50
|
|
2
|
|
9
|
my ( $self, $entry ) = @_ |
|
389
|
|
|
|
|
|
|
or die "Need entry"; |
|
390
|
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
$self->_git_clone_or_callback( $entry , |
|
392
|
|
|
|
|
|
|
sub { |
|
393
|
1
|
|
|
1
|
|
3
|
my( $msg , $entry ) = @_; |
|
394
|
|
|
|
|
|
|
|
|
395
|
1
|
|
|
|
|
36
|
my @o = $entry->pull; |
|
396
|
1
|
50
|
|
|
|
6
|
if ( $o[0] =~ /^Already up.to.date\./ ) { |
|
397
|
0
|
0
|
|
|
|
0
|
$msg .= $self->minor_change('Up to date') unless $self->quiet; |
|
398
|
|
|
|
|
|
|
} |
|
399
|
|
|
|
|
|
|
else { |
|
400
|
1
|
|
|
|
|
43
|
$msg .= $self->major_change('Updated'); |
|
401
|
1
|
50
|
|
|
|
29
|
$msg .= "\n" . join("\n",@o) unless $self->quiet; |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
|
|
404
|
1
|
|
|
|
|
44
|
return $msg; |
|
405
|
|
|
|
|
|
|
} |
|
406
|
2
|
|
|
|
|
38
|
); |
|
407
|
|
|
|
|
|
|
} |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub _path_is_managed { |
|
410
|
0
|
|
|
0
|
|
0
|
my( $self , $path ) = @_; |
|
411
|
|
|
|
|
|
|
|
|
412
|
0
|
0
|
|
|
|
0
|
return unless $path; |
|
413
|
|
|
|
|
|
|
|
|
414
|
0
|
|
|
|
|
0
|
my $dir = $self->_find_repo_root( $path ); |
|
415
|
0
|
|
|
|
|
0
|
my $max_len = $self->max_length_of_an_active_repo_label; |
|
416
|
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
0
|
for my $repo ( $self->active_repos ) { |
|
418
|
0
|
0
|
|
|
|
0
|
next unless $repo->path eq $dir->absolute; |
|
419
|
|
|
|
|
|
|
|
|
420
|
0
|
0
|
0
|
|
|
0
|
my $repo_remote = ( $repo->repo and -d $repo->path ) ? $repo->repo |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
: ( $repo->repo ) ? $repo->repo . ' (Not checked out)' |
|
422
|
|
|
|
|
|
|
: ( -d $repo->path ) ? 'NO REMOTE' |
|
423
|
|
|
|
|
|
|
: 'ERROR: No remote and no repo?!'; |
|
424
|
|
|
|
|
|
|
|
|
425
|
0
|
|
|
|
|
0
|
printf "%3d) ", $repo->number; |
|
426
|
|
|
|
|
|
|
|
|
427
|
0
|
0
|
|
|
|
0
|
if ( $self->quiet ) { say $repo->label } |
|
|
0
|
|
|
|
|
0
|
|
|
428
|
|
|
|
|
|
|
else { |
|
429
|
0
|
|
|
|
|
0
|
printf "%-${max_len}s %-4s %s\n", |
|
430
|
|
|
|
|
|
|
$repo->label, $repo->type, $repo_remote; |
|
431
|
0
|
0
|
|
|
|
0
|
if ( $self->verbose ) { |
|
432
|
0
|
0
|
|
|
|
0
|
printf " tags: %s\n" , $repo->tags if $repo->tags; |
|
433
|
|
|
|
|
|
|
} |
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
|
|
436
|
0
|
|
|
|
|
0
|
return 1; |
|
437
|
|
|
|
|
|
|
} |
|
438
|
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
0
|
say "repository not in Got list"; |
|
440
|
0
|
|
|
|
|
0
|
return; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
sub _read_config { |
|
444
|
37
|
|
|
37
|
|
1624
|
my $file = shift; |
|
445
|
|
|
|
|
|
|
|
|
446
|
37
|
|
|
|
|
108
|
my $config; |
|
447
|
|
|
|
|
|
|
|
|
448
|
37
|
100
|
|
|
|
845
|
if ( -e $file ) { |
|
449
|
29
|
|
|
29
|
|
2067
|
try { $config = LoadFile( $file ) } |
|
450
|
29
|
|
|
0
|
|
612
|
catch { say "Failed to parse config..."; exit }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
451
|
|
|
|
|
|
|
} |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
# if the config is completely empty, bootstrap _something_ |
|
454
|
37
|
|
100
|
|
|
311730
|
return $config // [ {} ]; |
|
455
|
|
|
|
|
|
|
} |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
sub _run_git_cherry { |
|
458
|
0
|
|
|
0
|
|
0
|
my( $self , $entry ) = @_; |
|
459
|
|
|
|
|
|
|
|
|
460
|
0
|
|
|
|
|
0
|
my $msg = ''; |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
try { |
|
463
|
0
|
0
|
|
0
|
|
0
|
if ( $entry->remote ) { |
|
464
|
0
|
|
|
|
|
0
|
my $cherry = $entry->cherry; |
|
465
|
0
|
0
|
|
|
|
0
|
if ( $cherry > 0 ) { |
|
466
|
0
|
|
|
|
|
0
|
$msg = $self->major_change("Ahead by $cherry"); |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
} |
|
469
|
|
|
|
|
|
|
} |
|
470
|
0
|
|
|
0
|
|
0
|
catch { $msg = $self->error('ERROR') . "\n$_" }; |
|
|
0
|
|
|
|
|
0
|
|
|
471
|
|
|
|
|
|
|
|
|
472
|
0
|
|
|
|
|
0
|
return $msg |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub _run_git_status { |
|
476
|
6
|
|
|
6
|
|
20
|
my( $self , $entry ) = @_; |
|
477
|
|
|
|
|
|
|
|
|
478
|
6
|
|
|
|
|
43
|
my %types = ( |
|
479
|
|
|
|
|
|
|
indexed => 'Changes to be committed' , |
|
480
|
|
|
|
|
|
|
changed => 'Changed but not updated' , |
|
481
|
|
|
|
|
|
|
unknown => 'Untracked files' , |
|
482
|
|
|
|
|
|
|
conflict => 'Files with conflicts' , |
|
483
|
|
|
|
|
|
|
); |
|
484
|
|
|
|
|
|
|
|
|
485
|
6
|
|
|
|
|
18
|
my( $msg , $verbose_msg ) = ('',''); |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
try { |
|
488
|
6
|
|
|
6
|
|
422
|
my $status = $entry->status; |
|
489
|
6
|
50
|
|
|
|
26
|
if ( keys %$status ) { |
|
490
|
0
|
|
|
|
|
0
|
$msg .= $self->warning('Dirty') . ' '; |
|
491
|
|
|
|
|
|
|
} else { |
|
492
|
6
|
50
|
|
|
|
160
|
$msg .= $self->minor_change('OK ') unless $self->quiet; |
|
493
|
|
|
|
|
|
|
} |
|
494
|
|
|
|
|
|
|
|
|
495
|
6
|
100
|
|
|
|
122
|
if ( $self->verbose ) { |
|
496
|
2
|
|
|
|
|
62
|
TYPE: for my $type ( keys %types ) { |
|
497
|
8
|
50
|
|
|
|
17
|
my @states = $status->get( $type ) or next TYPE; |
|
498
|
0
|
|
|
|
|
0
|
$verbose_msg .= "\n** $types{$type}:\n"; |
|
499
|
0
|
|
|
|
|
0
|
for ( @states ) { |
|
500
|
0
|
|
|
|
|
0
|
$verbose_msg .= sprintf ' %-12s %s' , $_->mode , $_->from; |
|
501
|
0
|
0
|
|
|
|
0
|
$verbose_msg .= sprintf ' -> %s' , $_->to if $_->mode eq 'renamed'; |
|
502
|
0
|
|
|
|
|
0
|
$verbose_msg .= "\n"; |
|
503
|
|
|
|
|
|
|
} |
|
504
|
|
|
|
|
|
|
} |
|
505
|
2
|
50
|
|
|
|
12
|
$verbose_msg = "\n$verbose_msg" if $verbose_msg; |
|
506
|
|
|
|
|
|
|
} |
|
507
|
|
|
|
|
|
|
} |
|
508
|
6
|
|
|
0
|
|
77
|
catch { $msg .= $self->error('ERROR') . "\n$_" }; |
|
|
0
|
|
|
|
|
0
|
|
|
509
|
|
|
|
|
|
|
|
|
510
|
6
|
|
|
|
|
270
|
return( $msg , $verbose_msg ); |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
sub _status { |
|
514
|
3
|
|
|
3
|
|
550
|
my( $self , @repos ) = @_; |
|
515
|
|
|
|
|
|
|
|
|
516
|
3
|
|
|
|
|
16
|
my $max_len = $self->max_length_of_an_active_repo_label; |
|
517
|
|
|
|
|
|
|
|
|
518
|
3
|
|
|
|
|
15
|
REPO: for my $repo ( @repos ) { |
|
519
|
12
|
|
|
|
|
194
|
my $label = $repo->label; |
|
520
|
|
|
|
|
|
|
|
|
521
|
12
|
|
|
|
|
87
|
my $msg = sprintf "%3d) %-${max_len}s : ", $repo->number, $label; |
|
522
|
|
|
|
|
|
|
|
|
523
|
12
|
|
|
|
|
26
|
my ( $status, $fxn ); |
|
524
|
|
|
|
|
|
|
|
|
525
|
12
|
100
|
|
|
|
262
|
if ( -d $repo->path ) { |
|
|
|
100
|
|
|
|
|
|
|
526
|
6
|
|
|
|
|
28
|
my $repo_type = $repo->type; |
|
527
|
6
|
50
|
|
|
|
17
|
if ( $repo_type eq 'git' ) { $fxn = '_git_status' } |
|
|
6
|
|
|
|
|
12
|
|
|
528
|
|
|
|
|
|
|
### FIXME elsif( $repo_type eq 'svn' ) { $fxn = 'svn_status' } |
|
529
|
0
|
|
|
|
|
0
|
else { $status = $self->error("ERROR: repo type '$repo_type' not supported") } |
|
530
|
|
|
|
|
|
|
|
|
531
|
6
|
50
|
|
|
|
37
|
$status = $self->$fxn($repo) if ($fxn); |
|
532
|
|
|
|
|
|
|
|
|
533
|
6
|
50
|
33
|
|
|
278
|
next REPO if $self->quiet and !$status; |
|
534
|
|
|
|
|
|
|
} |
|
535
|
3
|
|
|
|
|
15
|
elsif ( $repo->repo ) { $status = 'Not checked out' } |
|
536
|
3
|
|
|
|
|
91
|
else { $status = $self->error("ERROR: repo '$label' does not exist") } |
|
537
|
|
|
|
|
|
|
|
|
538
|
12
|
|
|
|
|
226
|
say "$msg$status"; |
|
539
|
|
|
|
|
|
|
} |
|
540
|
|
|
|
|
|
|
} |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
sub _update { |
|
543
|
1
|
|
|
1
|
|
237
|
my( $self , @repos ) = @_; |
|
544
|
|
|
|
|
|
|
|
|
545
|
1
|
|
|
|
|
9
|
my $max_len = $self->max_length_of_an_active_repo_label; |
|
546
|
|
|
|
|
|
|
|
|
547
|
1
|
|
|
|
|
4
|
REPO: for my $repo ( @repos ) { |
|
548
|
4
|
100
|
|
|
|
150
|
next REPO unless $repo->repo; |
|
549
|
|
|
|
|
|
|
|
|
550
|
2
|
|
|
|
|
12
|
my $name = $repo->name; |
|
551
|
|
|
|
|
|
|
|
|
552
|
2
|
|
|
|
|
42
|
my $msg = sprintf "%3d) %-${max_len}s : ", $repo->number, $repo->label; |
|
553
|
|
|
|
|
|
|
|
|
554
|
2
|
|
|
|
|
8
|
my ( $status, $fxn ); |
|
555
|
|
|
|
|
|
|
|
|
556
|
2
|
|
|
|
|
15
|
my $repo_type = $repo->type; |
|
557
|
|
|
|
|
|
|
|
|
558
|
2
|
50
|
|
|
|
9
|
if ( $repo_type eq 'git' ) { $fxn = '_git_update' } |
|
|
2
|
|
|
|
|
5
|
|
|
559
|
|
|
|
|
|
|
### FIXME elsif( $repo_type eq 'svn' ) { $fxn = 'svn_update' } |
|
560
|
0
|
|
|
|
|
0
|
else { $status = $self->error("ERROR: repo type '$_' not supported") } |
|
561
|
|
|
|
|
|
|
|
|
562
|
2
|
50
|
|
|
|
16
|
$status = $self->$fxn($repo) if ($fxn); |
|
563
|
|
|
|
|
|
|
|
|
564
|
2
|
50
|
33
|
|
|
49
|
next REPO if $self->quiet and !$status; |
|
565
|
|
|
|
|
|
|
|
|
566
|
2
|
|
|
|
|
72
|
say "$msg$status"; |
|
567
|
|
|
|
|
|
|
} |
|
568
|
|
|
|
|
|
|
} |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
# override this in commands that shouldn't use IO::Page -- i.e., ones that |
|
571
|
|
|
|
|
|
|
# need to do incremental output |
|
572
|
25
|
|
|
25
|
|
3137
|
sub _use_io_page { 1 } |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
1; |
|
576
|
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
__END__ |