line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Git::Workflow::Command::Feature; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2014-03-11 21:17:31 |
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
5
|
|
|
|
|
|
|
# $Id$ |
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
85428
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
58
|
|
10
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
11
|
2
|
|
|
2
|
|
408
|
use version; |
|
2
|
|
|
|
|
1554
|
|
|
2
|
|
|
|
|
13
|
|
12
|
2
|
|
|
2
|
|
558
|
use English qw/ -no_match_vars /; |
|
2
|
|
|
|
|
2987
|
|
|
2
|
|
|
|
|
11
|
|
13
|
2
|
|
|
2
|
|
1624
|
use App::Git::Workflow::Pom; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
96
|
|
14
|
2
|
|
|
2
|
|
450
|
use App::Git::Workflow::Command qw/get_options/; |
|
2
|
|
|
|
|
33
|
|
|
2
|
|
|
|
|
1474
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = version->new(1.1.16); |
17
|
|
|
|
|
|
|
our $workflow = App::Git::Workflow::Pom->new; |
18
|
|
|
|
|
|
|
our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs; |
19
|
|
|
|
|
|
|
our %option; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub run { |
22
|
10
|
|
100
|
10
|
1
|
37
|
%option = ( |
23
|
|
|
|
|
|
|
pom => $workflow->config('workflow.pom') || 'pom.xml', |
24
|
|
|
|
|
|
|
local => $workflow->config('workflow.pom-local'), |
25
|
|
|
|
|
|
|
fetch => 1, |
26
|
|
|
|
|
|
|
url => $workflow->config('jira.url'), |
27
|
|
|
|
|
|
|
); |
28
|
10
|
50
|
|
|
|
34
|
get_options( |
29
|
|
|
|
|
|
|
\%option, |
30
|
|
|
|
|
|
|
'tag|t=s', |
31
|
|
|
|
|
|
|
'branch|b=s', |
32
|
|
|
|
|
|
|
'local|l!', |
33
|
|
|
|
|
|
|
'pom|x=s', |
34
|
|
|
|
|
|
|
'url|u=s', |
35
|
|
|
|
|
|
|
'user|U=s', |
36
|
|
|
|
|
|
|
'pass|password|P=s', |
37
|
|
|
|
|
|
|
'jira|j=s', |
38
|
|
|
|
|
|
|
'fetch|f!', |
39
|
|
|
|
|
|
|
'new_pom|new-pom|n!', |
40
|
|
|
|
|
|
|
'push|p', |
41
|
|
|
|
|
|
|
) or return; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# do stuff here |
44
|
10
|
|
|
|
|
23
|
$workflow->{VERBOSE} = $option{verbose}; |
45
|
10
|
|
|
|
|
18
|
$workflow->{TEST } = $option{test}; |
46
|
|
|
|
|
|
|
|
47
|
10
|
100
|
|
|
|
25
|
my ($feature_branch) = @ARGV ? shift @ARGV : jira(); |
48
|
8
|
|
|
|
|
12
|
my ($type, $regex); |
49
|
8
|
100
|
|
|
|
20
|
if ($option{tag}) { |
|
|
100
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
$type = 'tag'; |
51
|
1
|
|
|
|
|
3
|
$regex = $option{tag}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($option{branch}) { |
54
|
1
|
|
|
|
|
3
|
$type = 'branch'; |
55
|
1
|
|
|
|
|
3
|
$regex = $option{branch}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
6
|
|
|
|
|
17
|
my $default = $workflow->config('workflow.prod'); |
59
|
|
|
|
|
|
|
my $prod |
60
|
|
|
|
|
|
|
= $default ? $default |
61
|
6
|
100
|
|
|
|
17
|
: $option{local} ? 'branch=^master$' |
|
|
100
|
|
|
|
|
|
62
|
|
|
|
|
|
|
: 'branch=^origin/master$'; |
63
|
6
|
|
|
|
|
29
|
($type, $regex) = split /\s*=\s*/, $prod; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
8
|
100
|
|
|
|
25
|
$workflow->git->fetch() if $option{fetch}; |
67
|
8
|
|
|
|
|
28
|
my $release = $workflow->release($type, $option{local}, $regex); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# checkout branch |
70
|
8
|
100
|
|
|
|
81
|
print "Created $feature_branch\n" if $option{verbose}; |
71
|
8
|
|
|
|
|
22
|
$workflow->git->checkout( '-b', $feature_branch, '--no-track', $release ); |
72
|
|
|
|
|
|
|
|
73
|
8
|
50
|
|
|
|
18
|
if ($option{new_pom}) { |
74
|
0
|
|
|
|
|
0
|
my $version = $workflow->next_pom_version($option{pom}); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
system(qw/mvn versions:set/, "–DnewVersion=$version"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# push if requested to |
80
|
8
|
100
|
|
|
|
14
|
if ($option{push}) { |
81
|
1
|
|
|
|
|
4
|
$workflow->git->push( qw/-u origin/, $feature_branch ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
8
|
|
|
|
|
17
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub jira { |
88
|
2
|
50
|
|
2
|
1
|
13
|
die "No JIRA specified!\n" if !$option{jira}; |
89
|
0
|
0
|
|
|
|
|
die "No JIRA url specified!\n" if !$option{url}; |
90
|
0
|
|
|
|
|
|
require JIRA::REST; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $jira_rest = JIRA::REST->new($option{url}, $option{user}, $option{pass}); |
93
|
0
|
|
|
|
|
|
my $issue = $jira_rest->GET("/issue/$option{jira}"); |
94
|
0
|
|
|
|
|
|
my $branch = lc "$option{jira} $issue->{fields}{summary}"; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# remove unsafe characters |
97
|
0
|
|
|
|
|
|
$branch =~ s/[&'" .:!?|\/\\-]+/_/gxms; |
98
|
|
|
|
|
|
|
# remove leading and trailing underscores |
99
|
0
|
|
|
|
|
|
$branch =~ s/^_+|_+$//gxms; |
100
|
|
|
|
|
|
|
# remove doubled underscores |
101
|
0
|
|
|
|
|
|
$branch =~ s/__+/_/gxms; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return $branch; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__DATA__ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
git-feature - Create a feature branch from the "current release" |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This documentation refers to git-feature version 1.1.16 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
git-feature [option] branch-name |
121
|
|
|
|
|
|
|
git-feature [option] [--jira|-j] JIRAID |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
OPTIONS: |
124
|
|
|
|
|
|
|
branch-name The name of the new branch to create from the current release branch/tag |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
-j --jira[=]JIRAID |
127
|
|
|
|
|
|
|
Find the summary for JIRA item JIRAID and make it the |
128
|
|
|
|
|
|
|
branch name for the feature. |
129
|
|
|
|
|
|
|
-u --url[=]URL Use URL as the JIRA instance for looking up summaries. |
130
|
|
|
|
|
|
|
-U --user[=]str JIRA user name to use when querying JIRA |
131
|
|
|
|
|
|
|
-P --password[=]str |
132
|
|
|
|
|
|
|
JIRA password for --user |
133
|
|
|
|
|
|
|
-t --tag[=]str Specify a tag that any branch with newer commits must contain |
134
|
|
|
|
|
|
|
-b --branch[=]str Similarly a branch that other branches with newer commits must |
135
|
|
|
|
|
|
|
contain (Default origin/master) |
136
|
|
|
|
|
|
|
-l --local Shorthand for --branch '^master$' |
137
|
|
|
|
|
|
|
-p --push Push the new brach upstream |
138
|
|
|
|
|
|
|
--no-fetch Don't fetch before trying to find the remote branch |
139
|
|
|
|
|
|
|
-n --new-pom Set the pom.xml version to the next available version |
140
|
|
|
|
|
|
|
-x --pom[=]dir/pom.xml |
141
|
|
|
|
|
|
|
The location of the master pom.xml if it isn't in the |
142
|
|
|
|
|
|
|
current directory. |
143
|
|
|
|
|
|
|
-t --test Test, don't actually run |
144
|
|
|
|
|
|
|
-v --verbose Show more details |
145
|
|
|
|
|
|
|
--version Prints the version information |
146
|
|
|
|
|
|
|
--help Prints this help information |
147
|
|
|
|
|
|
|
--man Prints the full documentation for git-feature |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 DESCRIPTION |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The C<git feature> command allows a simplified way to create and switch to |
152
|
|
|
|
|
|
|
feature branches using whatever you define as the I<current release>. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
By default I<current release> is defined as the I<origin/master> branch that |
155
|
|
|
|
|
|
|
can be changed either on the command line using the --tag or --branch |
156
|
|
|
|
|
|
|
arguments or by setting the C<workflow.prod> git config. Example of commonly |
157
|
|
|
|
|
|
|
used alternatives include using release version tags where you might use |
158
|
|
|
|
|
|
|
something like C<--tag ^v\d+[.]\d+'> to match tags like v0.1 or v1.0 etc. |
159
|
|
|
|
|
|
|
Other examples include different branches containing release versions of |
160
|
|
|
|
|
|
|
code. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The branch I<origin/master> is used over I<master> to save you from having |
163
|
|
|
|
|
|
|
to switch to master and pull any new changes. A C<git fetch> is called by |
164
|
|
|
|
|
|
|
default before branching to further ensure the latest version of code is |
165
|
|
|
|
|
|
|
available. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 C<run ()> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Executes the git workflow command |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 C<jira ()> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Create a branch name from the JIRA summary |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Defaults for this script can be set through C<git config> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
workflow.prod Sets how a prod release is determined |
184
|
|
|
|
|
|
|
eg the default equivalent is branch=^origin/master$ |
185
|
|
|
|
|
|
|
workflow.pom The default location for the pom.xml file (used by C<--new-pom> |
186
|
|
|
|
|
|
|
when updating pom.xml for the new branch) |
187
|
|
|
|
|
|
|
workflow.pom-local |
188
|
|
|
|
|
|
|
Can set default value of C<--local> |
189
|
|
|
|
|
|
|
jira.url Specifies the URL for the JIRA instance being used |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
You can set these values either by editing the repository local C<.git/config> |
192
|
|
|
|
|
|
|
file or C<~/.gitconfig> or use the C<git config> command |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# eg Setting the global value |
195
|
|
|
|
|
|
|
git config --global workflow.prod 'branch=^origin/master$' |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# or set a repository's local value |
198
|
|
|
|
|
|
|
git config workflow.prod 'tag=^release_\d{4}_\d{2}\d{2}$' |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# or setting pom.xml location to a sub directory |
201
|
|
|
|
|
|
|
git config workflow.pom 'somedir/pom.xml' |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
There are no known bugs in this module. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Patches are welcome. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 AUTHOR |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
222
|
|
|
|
|
|
|
All rights reserved. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
225
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
226
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
227
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
228
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |