File Coverage

blib/lib/App/Git/Workflow/Command/SinceRelease.pm
Criterion Covered Total %
statement 42 42 100.0
branch 10 12 83.3
condition 5 6 83.3
subroutine 9 9 100.0
pod 2 2 100.0
total 68 71 95.7


line stmt bran cond sub pod time code
1             package App::Git::Workflow::Command::SinceRelease;
2              
3             # Created on: 2014-03-11 20:58:59
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 2     2   43820 use strict;
  2         4  
  2         63  
10 2     2   9 use warnings;
  2         3  
  2         54  
11 2     2   1393 use Pod::Usage ();
  2         102449  
  2         69  
12 2     2   1458 use Data::Dumper qw/Dumper/;
  2         12428  
  2         177  
13 2     2   1260 use English qw/ -no_match_vars /;
  2         6214  
  2         13  
14 2     2   1882 use App::Git::Workflow;
  2         91655  
  2         133  
15 2     2   1642 use App::Git::Workflow::Command qw/get_options/;
  2         26310  
  2         917  
16              
17             our $VERSION = 0.3;
18             our $workflow = App::Git::Workflow->new;
19             our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
20             our %option;
21              
22             sub run {
23 4     4 1 12658 my ($self) = @_;
24              
25 4         18 get_options(
26             \%option,
27             'quiet|q',
28             );
29              
30             # get newest tag
31 4         1120 my $tag = $self->newest_tag;
32 4 50 66     24 return if $option{quiet} && !$tag;
33              
34             # get rev-parse --all -n 100
35             # stop processing when commit is tag
36 4         5 my $count = 0;
37 4         4 my %seen;
38 4         11 for my $id (reverse $workflow->git->rev_parse("--all")) {
39 8 100       108 next if $seen{$id}++;
40 5         13 my $details = $workflow->commit_details($id);
41 5 100       154 next if $details->{time} < $tag;
42 3         6 $count++;
43             }
44              
45 4 100 100     126 print "Ahead by $count commit" . ($count != 1 ? 's' : '') . "\n" if !$option{quiet} || $count;
    100          
46              
47 4         14 return;
48             }
49              
50             sub newest_tag {
51 4     4 1 7 my ($self) = @_;
52 4         7 my ($max_tag, $max_time) = ('', 0);
53              
54 4         14 for my $tag ($workflow->git->tag) {
55 8         158 my $details = $workflow->commit_details($tag);
56 8 50       275 if ($details->{time} > $max_time) {
57 8         10 $max_time = $details->{time};
58 8         20 $max_tag = $tag;
59             }
60             }
61              
62 4         8 return $max_time;
63             }
64              
65             1;
66              
67             __DATA__
68              
69             =head1 NAME
70              
71             App::Git::Workflow::Command::SinceRelease - Finds out how many commits a branch is since latest release
72              
73             =head1 VERSION
74              
75             This documentation refers to git-since-release version 0.3
76              
77             =head1 SYNOPSIS
78              
79             git-since-release [option]
80              
81             OPTIONS:
82             -q --quiet Suppress notifying of files changed
83              
84             -v --verbose Show more detailed option
85             --VERSION Prints the version information
86             --help Prints this help information
87             --man Prints the full documentation for git-since-release
88              
89             =head1 DESCRIPTION
90              
91             C<git-since-release> finds out how many commits the repository is since the
92             latest release (determined by the latest tag).
93              
94             =head1 SUBROUTINES/METHODS
95              
96             =head2 C<run ()>
97              
98             Executes the git workflow command
99              
100             =head2 C<newest_tag ()>
101              
102             Returns the most recently created tag
103              
104             =head1 DIAGNOSTICS
105              
106             =head1 CONFIGURATION AND ENVIRONMENT
107              
108             =head1 DEPENDENCIES
109              
110             =head1 INCOMPATIBILITIES
111              
112             =head1 BUGS AND LIMITATIONS
113              
114             There are no known bugs in this module.
115              
116             Please report problems to Ivan Wills (ivan.wills@gmail.com).
117              
118             Patches are welcome.
119              
120             =head1 AUTHOR
121              
122             Ivan Wills - (ivan.wills@gmail.com)
123              
124             =head1 LICENSE AND COPYRIGHT
125              
126             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
127             All rights reserved.
128              
129             This module is free software; you can redistribute it and/or modify it under
130             the same terms as Perl itself. See L<perlartistic>. This program is
131             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
132             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
133             PARTICULAR PURPOSE.
134              
135             =cut