line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Dist-Zilla-Plugin-Git |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2009 by Jerome Quelin. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
1
|
|
|
1
|
|
1411
|
use 5.008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
10
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
11
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
54
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::ACPS::Git::Commit; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: commit dirty files |
16
|
|
|
|
|
|
|
our $VERSION = '0.30'; # VERSION |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
701
|
use File::Temp qw{ tempfile }; |
|
1
|
|
|
|
|
15667
|
|
|
1
|
|
|
|
|
63
|
|
19
|
1
|
|
|
1
|
|
465
|
use Git::Wrapper; |
|
1
|
|
|
|
|
10306
|
|
|
1
|
|
|
|
|
30
|
|
20
|
1
|
|
|
1
|
|
200
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use MooseX::Has::Sugar; |
22
|
|
|
|
|
|
|
use MooseX::Types::Moose qw{ Str }; |
23
|
|
|
|
|
|
|
use Path::Class::Dir (); |
24
|
|
|
|
|
|
|
use Cwd; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use String::Formatter method_stringf => { |
27
|
|
|
|
|
|
|
-as => '_format_string', |
28
|
|
|
|
|
|
|
codes => { |
29
|
|
|
|
|
|
|
c => sub { $_[0]->_get_changes }, |
30
|
|
|
|
|
|
|
d => sub { require DateTime; |
31
|
|
|
|
|
|
|
DateTime->now(time_zone => $_[0]->time_zone) |
32
|
|
|
|
|
|
|
->format_cldr($_[1] || 'dd-MMM-yyyy') }, |
33
|
|
|
|
|
|
|
n => sub { "\n" }, |
34
|
|
|
|
|
|
|
N => sub { $_[0]->zilla->name }, |
35
|
|
|
|
|
|
|
t => sub { $_[0]->zilla->is_trial |
36
|
|
|
|
|
|
|
? (defined $_[1] ? $_[1] : '-TRIAL') : '' }, |
37
|
|
|
|
|
|
|
v => sub { $_[0]->zilla->version }, |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::Releaser'; |
42
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::Git::Repo'; |
43
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::Git::DirtyFiles'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# -- attributes |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has commit_msg => ( ro, isa=>Str, default => 'v%v%n%n%c' ); |
48
|
|
|
|
|
|
|
has time_zone => ( ro, isa=>Str, default => 'local' ); |
49
|
|
|
|
|
|
|
has add_files_in => ( ro, isa=>'ArrayRef[Str]', default => sub { [] } ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# -- public methods |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub mvp_multivalue_args { qw( add_files_in ) } |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub release { |
56
|
|
|
|
|
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $git = Git::Wrapper->new( $self->repo_root ); |
59
|
|
|
|
|
|
|
my @output; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# check if there are dirty files that need to be committed. |
62
|
|
|
|
|
|
|
# at this time, we know that only those 2 files may remain modified, |
63
|
|
|
|
|
|
|
# otherwise before_release would have failed, ending the release |
64
|
|
|
|
|
|
|
# process. |
65
|
|
|
|
|
|
|
@output = sort { lc $a cmp lc $b } $self->list_dirty_files($git, 1); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# add any other untracked files to the commit list |
68
|
|
|
|
|
|
|
if ( @{ $self->add_files_in } ) { |
69
|
|
|
|
|
|
|
my @untracked_files = $git->ls_files( { others=>1, 'exclude-standard'=>1 } ); |
70
|
|
|
|
|
|
|
foreach my $f ( @untracked_files ) { |
71
|
|
|
|
|
|
|
foreach my $path ( @{ $self->add_files_in } ) { |
72
|
|
|
|
|
|
|
if ( Path::Class::Dir->new( $path )->subsumes( $f ) ) { |
73
|
|
|
|
|
|
|
push( @output, $f ); |
74
|
|
|
|
|
|
|
last; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# if nothing to commit, we're done! |
81
|
|
|
|
|
|
|
return unless @output; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# write commit message in a temp file |
84
|
|
|
|
|
|
|
my ($fh, $filename) = tempfile( getcwd . '/DZP-git.XXXX', UNLINK => 1 ); |
85
|
|
|
|
|
|
|
print $fh $self->get_commit_message; |
86
|
|
|
|
|
|
|
close $fh; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# commit the files in git |
89
|
|
|
|
|
|
|
$git->add( @output ); |
90
|
|
|
|
|
|
|
$self->log_debug($_) for $git->commit( { file=>$filename } ); |
91
|
|
|
|
|
|
|
$self->log("Committed @output"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_commit_message { |
97
|
|
|
|
|
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return _format_string($self->commit_msg, $self); |
100
|
|
|
|
|
|
|
} # end get_commit_message |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# -- private methods |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _get_changes { |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# parse changelog to find commit message |
108
|
|
|
|
|
|
|
my $changelog = Dist::Zilla::File::OnDisk->new( { name => $self->changelog } ); |
109
|
|
|
|
|
|
|
my $newver = $self->zilla->version; |
110
|
|
|
|
|
|
|
my @content = |
111
|
|
|
|
|
|
|
grep { /^$newver(?:\s+|$)/ ... /^\S/ } # from newver to un-indented |
112
|
|
|
|
|
|
|
split /\n/, $changelog->content; |
113
|
|
|
|
|
|
|
shift @content; # drop the version line |
114
|
|
|
|
|
|
|
# drop unindented last line and trailing blank lines |
115
|
|
|
|
|
|
|
pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# return commit message |
118
|
|
|
|
|
|
|
return join("\n", @content, ''); # add a final \n |
119
|
|
|
|
|
|
|
} # end _get_changes |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=pod |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Dist::Zilla::Plugin::ACPS::Git::Commit - commit dirty files |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 VERSION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
version 0.30 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SYNOPSIS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
In your F<dist.ini>: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
[ACPS::Git::Commit] |
144
|
|
|
|
|
|
|
changelog = Changes ; this is the default |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Forked from Dist::Zilla::Plugin::Git::Commit, to do the commit during the |
149
|
|
|
|
|
|
|
release step instead of after_release. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Once the release is done, this plugin will record this fact in git by |
152
|
|
|
|
|
|
|
committing changelog and F<dist.ini>. The commit message will be taken |
153
|
|
|
|
|
|
|
from the changelog for this release. It will include lines between |
154
|
|
|
|
|
|
|
the current version and timestamp and the next non-indented line. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The plugin accepts the following options: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * changelog - the name of your changelog file. Defaults to F<Changes>. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * allow_dirty - a file that will be checked in if it is locally |
163
|
|
|
|
|
|
|
modified. This option may appear multiple times. The default |
164
|
|
|
|
|
|
|
list is F<dist.ini> and the changelog file given by C<changelog>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * add_files_in - a path that will have its new files checked in. |
167
|
|
|
|
|
|
|
This option may appear multiple times. This is used to add files |
168
|
|
|
|
|
|
|
generated during build-time to the repository, for example. The default |
169
|
|
|
|
|
|
|
list is empty. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Note: The files have to be generated between those phases: BeforeRelease |
172
|
|
|
|
|
|
|
E<lt>-E<gt> AfterRelease, and after Git::Check + before Git::Commit. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * commit_msg - the commit message to use. Defaults to |
175
|
|
|
|
|
|
|
C<v%v%n%n%c>, meaning the version number and the list of changes. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * time_zone - the time zone to use with C<%d>. Can be any |
178
|
|
|
|
|
|
|
time zone name accepted by DateTime. Defaults to C<local>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
You can use the following codes in commit_msg: |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item C<%c> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The list of changes in the just-released version (read from C<changelog>). |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item C<%{dd-MMM-yyyy}d> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The current date. You can use any CLDR format supported by |
193
|
|
|
|
|
|
|
L<DateTime>. A bare C<%d> means C<%{dd-MMM-yyyy}d>. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item C<%n> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
a newline |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C<%N> |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
the distribution name |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item C<%{-TRIAL}t> |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Expands to -TRIAL (or any other supplied string) if this is a trial |
206
|
|
|
|
|
|
|
release, or the empty string if not. A bare C<%t> means C<%{-TRIAL}t>. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item C<%v> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
the distribution version |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 NAME |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Dist::Zilla::Plugin::ACPS::Git::Commit - commit dirty files |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 METHODS |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 get_commit_message |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This method returns the commit message. The default implementation |
223
|
|
|
|
|
|
|
reads the Changes file to get the list of changes in the just-released version. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=for Pod::Coverage after_release mvp_multivalue_args |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 AUTHOR |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Jerome Quelin |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Jerome Quelin. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
236
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 AUTHOR |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Graham Ollis <gollis@sesda3.com> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This software is copyright (c) 2012 by NASA GSFC. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
247
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__END__ |
253
|
|
|
|
|
|
|
|