line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::TagVersion; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1827
|
use Moose; |
|
1
|
|
|
|
|
494871
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.01'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: module to manage version tags in git |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7767
|
use Git::TagVersion::Version; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
1064
|
use Git::Wrapper; |
|
1
|
|
|
|
|
36993
|
|
|
1
|
|
|
|
|
597
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'fetch' => ( is => 'rw', isa => 'Bool', default => 0 ); |
13
|
|
|
|
|
|
|
has 'push' => ( is => 'rw', isa => 'Bool', default => 0 ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'root' => ( is => 'ro', isa => 'Str', default => '.' ); |
16
|
|
|
|
|
|
|
has 'repo' => ( |
17
|
|
|
|
|
|
|
is => 'ro', isa => 'Git::Wrapper', lazy => 1, |
18
|
|
|
|
|
|
|
default => sub { |
19
|
|
|
|
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
return Git::Wrapper->new( $self->root ); |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'version_regex' => ( is => 'ro', isa => 'Str', default => '^v(\d.+)$' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'versions' => ( |
27
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef[Git::TagVersion::Version]', lazy => 1, |
28
|
|
|
|
|
|
|
default => sub { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
my @versions; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if( $self->fetch ) { |
33
|
|
|
|
|
|
|
$self->repo->fetch; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $regex = $self->version_regex; |
37
|
|
|
|
|
|
|
foreach my $tag ( $self->repo->tag ) { |
38
|
|
|
|
|
|
|
if( my ($v_str) = $tag =~ /$regex/) { |
39
|
|
|
|
|
|
|
my $version; |
40
|
|
|
|
|
|
|
eval { |
41
|
|
|
|
|
|
|
$version = Git::TagVersion::Version->new( |
42
|
|
|
|
|
|
|
repo => $self->repo, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
$version->parse_version( $v_str ); |
45
|
|
|
|
|
|
|
$version->tag( $tag ); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
if( $@ ) { next; } |
48
|
|
|
|
|
|
|
push( @versions, $version ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
@versions = sort @versions; |
52
|
|
|
|
|
|
|
my $prev; |
53
|
|
|
|
|
|
|
foreach my $version ( @versions ) { |
54
|
|
|
|
|
|
|
if( defined $prev ) { |
55
|
|
|
|
|
|
|
$version->prev( $prev ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
$prev = $version; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
@versions = reverse @versions; |
61
|
|
|
|
|
|
|
return \@versions; |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has 'last_version' => ( |
66
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1, |
67
|
|
|
|
|
|
|
default => sub { |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
return( $self->versions->[0] ); |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has 'incr_level' => ( is => 'rw', isa => 'Int', default => 0 ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has 'add_level' => ( is => 'rw', isa => 'Int', default => 0 ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has 'next_version' => ( |
78
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1, |
79
|
|
|
|
|
|
|
default => sub { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
if( ! defined $self->last_version ) { |
82
|
|
|
|
|
|
|
return; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
if( $self->incr_level && $self->add_level ) { |
85
|
|
|
|
|
|
|
die('use increment or new minor version, not both'); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
my $next = $self->last_version->clone; |
88
|
|
|
|
|
|
|
if( $self->add_level ) { |
89
|
|
|
|
|
|
|
$next->add_level( $self->add_level ); |
90
|
|
|
|
|
|
|
} else { |
91
|
|
|
|
|
|
|
$next->increment( $self->incr_level ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
return $next; |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub tag_next_version { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my $next = $self->next_version; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if( ! defined $next ) { |
102
|
0
|
|
|
|
|
|
die('next version is not defined'); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $tag = 'v'.$next->as_string; |
106
|
0
|
|
|
|
|
|
$self->repo->tag($tag); |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if( $self->push ) { |
109
|
0
|
|
|
|
|
|
$self->repo->push('origin', $tag); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $tag; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=pod |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=encoding UTF-8 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 NAME |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Git::TagVersion - module to manage version tags in git |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 VERSION |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
version 1.01 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Markus Benning <ich@markusbenning.de>. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
140
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |