line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::TagVersion; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2351
|
use Moose; |
|
1
|
|
|
|
|
503916
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.00'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: module to manage version tags in git |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7788
|
use Git::TagVersion::Version; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
1012
|
use Git::Wrapper; |
|
1
|
|
|
|
|
41163
|
|
|
1
|
|
|
|
|
645
|
|
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 { $version = Git::TagVersion::Version->new_from_string( $v_str ) }; |
41
|
|
|
|
|
|
|
if( $@ ) { next; } |
42
|
|
|
|
|
|
|
push( @versions, $version ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return [ reverse sort @versions ]; |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'last_version' => ( |
50
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1, |
51
|
|
|
|
|
|
|
default => sub { |
52
|
|
|
|
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
return( $self->versions->[0] ); |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has 'incr_level' => ( is => 'rw', isa => 'Int', default => 0 ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has 'add_level' => ( is => 'rw', isa => 'Int', default => 0 ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'next_version' => ( |
62
|
|
|
|
|
|
|
is => 'ro', isa => 'Maybe[Git::TagVersion::Version]', lazy => 1, |
63
|
|
|
|
|
|
|
default => sub { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
if( ! defined $self->last_version ) { |
66
|
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
if( $self->incr_level && $self->add_level ) { |
69
|
|
|
|
|
|
|
die('use increment or new minor version, not both'); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
my $next = $self->last_version->clone; |
72
|
|
|
|
|
|
|
if( $self->add_level ) { |
73
|
|
|
|
|
|
|
$next->add_level( $self->add_level ); |
74
|
|
|
|
|
|
|
} else { |
75
|
|
|
|
|
|
|
$next->increment( $self->incr_level ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
return $next; |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub tag_next_version { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my $next = $self->next_version; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if( ! defined $next ) { |
86
|
0
|
|
|
|
|
|
die('next version is not defined'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $tag = 'v'.$next->as_string; |
90
|
0
|
|
|
|
|
|
$self->repo->tag($tag); |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if( $self->push ) { |
93
|
0
|
|
|
|
|
|
$self->repo->push('origin', $tag); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $tag; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=encoding UTF-8 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Git::TagVersion - module to manage version tags in git |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 VERSION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
version 1.00 |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Markus Benning <me@w3r3wolf.de>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
124
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |