File Coverage

blib/lib/Dist/Zilla/Plugin/Git/Tag.pm
Criterion Covered Total %
statement 33 34 97.0
branch 6 8 75.0
condition n/a
subroutine 10 11 90.9
pod 0 2 0.0
total 49 55 89.0


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 5     5   2204440 use 5.008;
  5         22  
10 5     5   34 use strict;
  5         14  
  5         173  
11 5     5   36 use warnings;
  5         11  
  5         460  
12              
13             package Dist::Zilla::Plugin::Git::Tag;
14             # ABSTRACT: Tag the new version
15              
16             our $VERSION = '2.048';
17              
18 5     5   37 use Moose;
  5         26  
  5         70  
19 5     5   39053 use MooseX::Has::Sugar;
  5         1707  
  5         53  
20 5     5   1963 use Types::Standard qw{ Str Bool};
  5         182063  
  5         68  
21 5     5   4410 use namespace::autoclean;
  5         14  
  5         60  
22              
23             sub _git_config_mapping { +{
24 0     0   0 changelog => '%{changelog}s',
25             } }
26              
27             # -- attributes
28              
29             has tag_format => ( ro, isa=>Str, default => 'v%V' );
30             has tag_message => ( ro, isa=>Str, default => 'v%V' );
31             has changelog => ( ro, isa=>Str, default => 'Changes' );
32             has branch => ( ro, isa=>Str, predicate=>'has_branch' );
33             has signed => ( ro, isa=>Bool, default=>0 );
34              
35             with 'Dist::Zilla::Role::BeforeRelease',
36             'Dist::Zilla::Role::AfterRelease',
37             'Dist::Zilla::Role::Git::Repo';
38             with 'Dist::Zilla::Role::Git::StringFormatter';
39             with 'Dist::Zilla::Role::GitConfig';
40              
41             #pod =method tag
42             #pod
43             #pod my $tag = $plugin->tag;
44             #pod
45             #pod Return the tag that will be / has been applied by the plugin. That is,
46             #pod returns C<tag_format> as completed with the real values.
47             #pod
48             #pod =cut
49              
50             has tag => ( ro, isa => Str, lazy_build => 1, );
51              
52             sub _build_tag
53             {
54 7     7   54 my $self = shift;
55 7         299 return $self->_format_string($self->tag_format);
56             }
57              
58              
59             # -- role implementation
60              
61             around dump_config => sub
62             {
63             my $orig = shift;
64             my $self = shift;
65              
66             my $config = $self->$orig;
67              
68             $config->{+__PACKAGE__} = {
69             (map +($_ => $self->$_), qw(tag_format tag_message changelog branch tag)),
70             signed => $self->signed ? 1 : 0,
71             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
72             };
73              
74             return $config;
75             };
76              
77             sub before_release {
78 9     9 0 980908 my $self = shift;
79              
80             # Make sure a tag with the new version doesn't exist yet:
81 9         645 my $tag = $self->tag;
82 9 100       279 $self->log_fatal("tag $tag already exists")
83             if $self->git->tag('-l', $tag );
84             }
85              
86             sub after_release {
87 5     5 0 29378 my $self = shift;
88              
89 5         54 my @opts;
90 5 50       320 push @opts, ( '-m' => $self->_format_string($self->tag_message) )
91             if $self->tag_message; # Make an annotated tag if tag_message, lightweight tag otherwise:
92 5 100       902 push @opts, '-s'
93             if $self->signed; # make a GPG-signed tag
94              
95 5 50       281 my @branch = $self->has_branch ? ( $self->branch ) : ();
96              
97             # create a tag with the new version
98 5         260 my $tag = $self->tag;
99 5         165 $self->git->tag( @opts, $tag, @branch );
100 5         76951 $self->log("Tagged $tag");
101             }
102              
103             __PACKAGE__->meta->make_immutable;
104             1;
105              
106             __END__
107              
108             =pod
109              
110             =encoding UTF-8
111              
112             =head1 NAME
113              
114             Dist::Zilla::Plugin::Git::Tag - Tag the new version
115              
116             =head1 VERSION
117              
118             version 2.048
119              
120             =head1 SYNOPSIS
121              
122             In your F<dist.ini>:
123              
124             [Git::Tag]
125             tag_format = v%V ; this is the default
126             tag_message = v%V ; this is the default
127              
128             =head1 DESCRIPTION
129              
130             Once the release is done, this plugin will record this fact in git by
131             creating a tag. By default, it makes an annotated tag. You can set
132             the C<tag_message> attribute to change the message. If you set
133             C<tag_message> to the empty string, it makes a lightweight tag.
134              
135             It also checks before the release to ensure the tag to be created
136             doesn't already exist. (You would have to manually delete the
137             existing tag before you could release the same version again, but that
138             is almost never a good idea.)
139              
140             =head2 Plugin options
141              
142             The plugin accepts the following options:
143              
144             =over 4
145              
146             =item * tag_format - format of the tag to apply. Defaults to C<v%V>.
147              
148             =item * tag_message - format of the tag annotation. Defaults to C<v%V>.
149             Use S<C<tag_message =>> to create a lightweight tag.
150             The L<formatting codes|Dist::Zilla::Role::Git::StringFormatter/DESCRIPTION>
151             used in C<tag_format> and C<tag_message> are documented under
152             L<Dist::Zilla::Role::Git::StringFormatter>.
153              
154             =item * time_zone - the time zone to use with C<%d>. Can be any
155             time zone name accepted by DateTime. Defaults to C<local>.
156              
157             =item * branch - which branch to tag. Defaults to the current branch.
158              
159             =item * signed - whether to make a GPG-signed tag, using the default
160             e-mail address's key. Consider setting C<user.signingkey> if C<gpg>
161             can't find the correct key:
162              
163             $ git config user.signingkey 450F89EC
164              
165             =back
166              
167             =head1 METHODS
168              
169             =head2 tag
170              
171             my $tag = $plugin->tag;
172              
173             Return the tag that will be / has been applied by the plugin. That is,
174             returns C<tag_format> as completed with the real values.
175              
176             =for Pod::Coverage after_release
177             before_release
178              
179             =head1 SUPPORT
180              
181             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Git>
182             (or L<bug-Dist-Zilla-Plugin-Git@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Git@rt.cpan.org>).
183              
184             There is also a mailing list available for users of this distribution, at
185             L<http://dzil.org/#mailing-list>.
186              
187             There is also an irc channel available for users of this distribution, at
188             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
189              
190             =head1 AUTHOR
191              
192             Jerome Quelin
193              
194             =head1 COPYRIGHT AND LICENCE
195              
196             This software is copyright (c) 2009 by Jerome Quelin.
197              
198             This is free software; you can redistribute it and/or modify it under
199             the same terms as the Perl 5 programming language system itself.
200              
201             =cut