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.014';
13             # ABSTRACT: Check your repo for fixup! and squash! before release
14              
15 1     1   280430 use Moose;
  1         101294  
  1         5  
16 1     1   5000 use namespace::autoclean;
  1         5168  
  1         3  
17 1     1   512 use MooseX::AttributeShortcuts;
  1         237374  
  1         5  
18              
19 1     1   24502 use autodie 'system';
  1         1  
  1         7  
20 1     1   237 use IPC::System::Simple ();
  1         1  
  1         18  
21              
22             # we depend on functionality first present in 1.120370
23 1     1   631 use Dist::Zilla::Plugin::Git::NextVersion 1.120370 ();
  1         637616  
  1         34  
24 1     1   8 use List::Util 'first';
  1         2  
  1         67  
25 1     1   5 use Try::Tiny;
  1         1  
  1         468  
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   7 my $self = shift @_;
44              
45             return
46 3     3   1090 first { $_->isa('Dist::Zilla::Plugin::Git::NextVersion') }
47 3         21 @{ $self->zilla->plugins_with(-VersionProvider) }
  3         96  
48             ;
49             }
50              
51             sub before_release {
52 3     3 0 277331 my $self = shift @_;
53              
54 3         111 my $repo = $self->_repo;
55 3         128 my $last_ver = $self->last_version;
56              
57             ### $last_ver
58              
59 3         22 my $log_opts = { pretty => 'oneline', 'abbrev-commit' => 1 };
60 3         4 my @logs;
61 3 50       12 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         110 @logs = $self->_repo->log($log_opts);
77             }
78              
79             my $_checker = sub {
80 6     6   14 my $lookfor = shift;
81              
82             return
83 2         23 map { $_ =~ s/\n.*$//; $_ }
  2         6  
84 2         13 map { $_->id . ': ' . $_->message }
85 6         14 grep { $_->message =~ /^$lookfor! / }
  34         194  
86             @logs;
87 3         36302 };
88              
89             ### @logs
90 3         13 my @fixups = $_checker->('fixup');
91 3         21 my @squashes = $_checker->('squash');
92              
93 3 100 100     30 if (@fixups || @squashes) {
94              
95 2         27 $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         13 $self->log('No fixup or squash commits found; OK to release');
103 1         468 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.014 of Dist::Zilla::Plugin::Git::CheckFor::Fixups - released October 10, 2016 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 BUGS
179              
180             Please report any bugs or feature requests on the bugtracker website
181             L<https://github.com/RsrchBoy/dist-zilla-pluginbundle-git-checkfor/issues>
182              
183             When submitting a bug or request, please include a test-file or a
184             patch to an existing test-file that illustrates the bug or desired
185             feature.
186              
187             =head1 AUTHOR
188              
189             Chris Weyl <cweyl@alumni.drew.edu>
190              
191             =head2 I'm a material boy in a material world
192              
193             =begin html
194              
195             <a href="https://gratipay.com/RsrchBoy/"><img src="http://img.shields.io/gratipay/RsrchBoy.svg" /></a>
196             <a href="http://bit.ly/rsrchboys-wishlist"><img src="http://wps.io/wp-content/uploads/2014/05/amazon_wishlist.resized.png" /></a>
197             <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>
198              
199             =end html
200              
201             Please note B<I do not expect to be gittip'ed or flattr'ed for this work>,
202             rather B<it is simply a very pleasant surprise>. I largely create and release
203             works like this because I need them or I find it enjoyable; however, don't let
204             that stop you if you feel like it ;)
205              
206             L<Flattr|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>,
207             L<Gratipay|https://gratipay.com/RsrchBoy/>, or indulge my
208             L<Amazon Wishlist|http://bit.ly/rsrchboys-wishlist>... If and *only* if you so desire.
209              
210             =head1 COPYRIGHT AND LICENSE
211              
212             This software is Copyright (c) 2012 by Chris Weyl.
213              
214             This is free software, licensed under:
215              
216             The GNU Lesser General Public License, Version 2.1, February 1999
217              
218             =cut