File Coverage

blib/lib/Dist/Zilla/Plugin/Git/CheckFor/Fixups.pm
Criterion Covered Total %
statement 48 51 94.1
branch 3 4 75.0
condition 3 3 100.0
subroutine 12 14 85.7
pod 0 1 0.0
total 66 73 90.4


line stmt bran cond sub pod time code
1             #
2             # This file is part of Dist-Zilla-PluginBundle-Git-CheckFor
3             #
4             # This software is Copyright (c) 2012 by Chris Weyl.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package Dist::Zilla::Plugin::Git::CheckFor::Fixups;
11             our $AUTHORITY = 'cpan:RSRCHBOY';
12             $Dist::Zilla::Plugin::Git::CheckFor::Fixups::VERSION = '0.012';
13             # ABSTRACT: Check your repo for fixup! and squash! before release
14              
15 1     1   566458 use Moose;
  1         3  
  1         7  
16 1     1   5564 use namespace::autoclean;
  1         1161  
  1         4  
17 1     1   538 use MooseX::AttributeShortcuts;
  1         235845  
  1         7  
18              
19 1     1   23771 use autodie 'system';
  1         2  
  1         7  
20 1     1   252 use IPC::System::Simple ();
  1         1  
  1         17  
21              
22             # we depend on functionality first present in 1.120370
23 1     1   691 use Dist::Zilla::Plugin::Git::NextVersion 1.120370 ();
  1         684491  
  1         39  
24 1     1   8 use List::Util 'first';
  1         1  
  1         75  
25 1     1   4 use Try::Tiny;
  1         2  
  1         505  
26              
27             # debugging...
28             #use Smart::Comments;
29              
30             with
31             'Dist::Zilla::Role::BeforeRelease',
32             'Dist::Zilla::Role::Git::Repo::More',
33             #-excludes => [ qw { _build_version_regexp _build_first_version } ],
34             ;
35              
36             has _next_version_plugin => (
37             is => 'lazy',
38             isa => 'Dist::Zilla::Plugin::Git::NextVersion',
39             handles => [ qw{ version_regexp first_version } ],
40             );
41              
42             sub _build__next_version_plugin {
43 3     3   8 my $self = shift @_;
44              
45             return
46 3     3   1238 first { $_->isa('Dist::Zilla::Plugin::Git::NextVersion') }
47 3         30 @{ $self->zilla->plugins_with(-VersionProvider) }
  3         104  
48             ;
49             }
50              
51             sub before_release {
52 3     3 0 342059 my $self = shift @_;
53              
54 3         150 my $repo = $self->_repo;
55 3         166 my $last_ver = $self->last_version;
56              
57             ### $last_ver
58              
59 3         30 my $log_opts = { pretty => 'oneline', 'abbrev-commit' => 1 };
60 3         11 my @logs;
61 3 50       13 if (defined $last_ver) {
62              
63             # FIXME this should be corrected to work in a cleaner fashion,
64             # possibly by mucking around with version_regexp and the tags in here,
65             # or by splitting the common git stuff out into a stash and accessing
66             # that, etc, etc
67             #
68             # But for now, this allows tags generated with a '-TRIAL' appended to
69             # them to be found and used without too much fuss.
70              
71 0     0   0 try { @logs = $self->_repo->log($log_opts, "$last_ver..HEAD") }
72 0     0   0 catch { @logs = $self->_repo->log($log_opts, "$last_ver-TRIAL..HEAD") }
73 0         0 ;
74             }
75             else {
76 3         146 @logs = $self->_repo->log($log_opts);
77             }
78              
79             my $_checker = sub {
80 6     6   17 my $lookfor = shift;
81              
82             return
83 2         33 map { $_ =~ s/\n.*$//; $_ }
  2         10  
  2         18  
84 34         280 map { $_->id . ': ' . $_->message }
85 6         15 grep { $_->message =~ /^$lookfor! / }
86             @logs;
87 3         47894 };
88              
89             ### @logs
90 3         22 my @fixups = $_checker->('fixup');
91 3         27 my @squashes = $_checker->('squash');
92              
93 3 100 100     49 if (@fixups || @squashes) {
94              
95 2         30 $self->log_fatal(
96             "Aborting release; found squash or fixup commits:\n\n"
97             . join("\n", @fixups)
98             . join("\n", @squashes)
99             );
100             }
101              
102 1         23 $self->log('No fixup or squash commits found; OK to release');
103 1         858 return;
104             }
105              
106              
107             __PACKAGE__->meta->make_immutable;
108              
109             !!42;
110              
111             __END__
112              
113             =pod
114              
115             =encoding UTF-8
116              
117             =for :stopwords Chris Weyl Christian Doherty Etheridge Karen Mengué Mike Olivier Walde
118              
119             =for :stopwords Wishlist flattr flattr'ed gittip gittip'ed
120              
121             =head1 NAME
122              
123             Dist::Zilla::Plugin::Git::CheckFor::Fixups - Check your repo for fixup! and squash! before release
124              
125             =head1 VERSION
126              
127             This document describes version 0.012 of Dist::Zilla::Plugin::Git::CheckFor::Fixups - released February 23, 2015 as part of Dist-Zilla-PluginBundle-Git-CheckFor.
128              
129             =head1 SYNOPSIS
130              
131             ; in dist.ini -- note we depend on Git::NextVersion for versioning info
132             [Git::NextVersion]
133             [Git::CheckFor::Fixups]
134              
135             =head1 DESCRIPTION
136              
137             This is a simple L<Dist::Zilla> plugin to check that since the last release,
138             you have no fixup or squash commits remaining in your history. The presence
139             of these commits is almost certainly an oversight, so if any are found the
140             release is aborted.
141              
142             Note that we do not check for the presence of such commits in the history of
143             older releases; having a fixup commit in the history is embarrassing, but not
144             so much so as rebasing to resolve a blemish in the deep, dark, sordid past of
145             the project.
146              
147             =for Pod::Coverage before_release
148              
149             =head1 WHAT'S A FIXUP OR SQUASH COMMIT?
150              
151             A squash or fixup commit is one with a commit message formatted in such a
152             manner that C<git rebase --autosquash> will recognize it; namely:
153              
154             A fixup commit has a commit message beginning with 'fixup! '
155              
156             A squash commit has a commit message beginning with 'squash! '
157              
158             =head1 SEE ALSO
159              
160             Please see those modules/websites for more information related to this module.
161              
162             =over 4
163              
164             =item *
165              
166             L<Dist::Zilla::PluginBundle::Git::CheckFor|Dist::Zilla::PluginBundle::Git::CheckFor>
167              
168             =item *
169              
170             L<Dist::Zilla>
171              
172             =item *
173              
174             L<Dist::Zilla::Plugin::Git::NextVersion>
175              
176             =back
177              
178             =head1 SOURCE
179              
180             The development version is on github at L<http://https://github.com/RsrchBoy/dist-zilla-pluginbundle-git-checkfor>
181             and may be cloned from L<git://https://github.com/RsrchBoy/dist-zilla-pluginbundle-git-checkfor.git>
182              
183             =head1 BUGS
184              
185             Please report any bugs or feature requests on the bugtracker website
186             https://github.com/RsrchBoy/dist-zilla-pluginbundle-git-checkfor/issues
187              
188             When submitting a bug or request, please include a test-file or a
189             patch to an existing test-file that illustrates the bug or desired
190             feature.
191              
192             =head1 AUTHOR
193              
194             Chris Weyl <cweyl@alumni.drew.edu>
195              
196             =head2 I'm a material boy in a material world
197              
198             =begin html
199              
200             <a href="https://www.gittip.com/RsrchBoy/"><img src="https://raw.githubusercontent.com/gittip/www.gittip.com/master/www/assets/%25version/logo.png" /></a>
201             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
202             <a href="https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fdist-zilla-pluginbundle-git-checkfor&title=RsrchBoy's%20CPAN%20Dist-Zilla-PluginBundle-Git-CheckFor&tags=%22RsrchBoy's%20Dist-Zilla-PluginBundle-Git-CheckFor%20in%20the%20CPAN%22"><img src="http://api.flattr.com/button/flattr-badge-large.png" /></a>
203              
204             =end html
205              
206             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
207             rather B<it is simply a very pleasant surprise>. I largely create and release
208             works like this because I need them or I find it enjoyable; however, don't let
209             that stop you if you feel like it ;)
210              
211             L<Flattr this|https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fdist-zilla-pluginbundle-git-checkfor&title=RsrchBoy's%20CPAN%20Dist-Zilla-PluginBundle-Git-CheckFor&tags=%22RsrchBoy's%20Dist-Zilla-PluginBundle-Git-CheckFor%20in%20the%20CPAN%22>,
212             L<gittip me|https://www.gittip.com/RsrchBoy/>, or indulge my
213             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If you so desire.
214              
215             =head1 COPYRIGHT AND LICENSE
216              
217             This software is Copyright (c) 2012 by Chris Weyl.
218              
219             This is free software, licensed under:
220              
221             The GNU Lesser General Public License, Version 2.1, February 1999
222              
223             =cut