File Coverage

blib/lib/App/Git/Workflow/Command/Branches.pm
Criterion Covered Total %
statement 35 49 71.4
branch 5 20 25.0
condition 0 3 0.0
subroutine 7 7 100.0
pod 1 1 100.0
total 48 80 60.0


line stmt bran cond sub pod time code
1              
2             # Created on: 2017-09-28 09:32:00
3             # Create by: Ivan Wills
4             # $Id$
5             # $Revision$, $HeadURL$, $Date$
6             # $Revision$, $Source$, $Date$
7              
8             use strict;
9 2     2   76006 use warnings;
  2         10  
  2         47  
10 2     2   9 use version;
  2         3  
  2         51  
11 2     2   332 use English qw/ -no_match_vars /;
  2         1381  
  2         10  
12 2     2   502 use App::Git::Workflow;
  2         2561  
  2         9  
13 2     2   883 use App::Git::Workflow::Command qw/get_options/;
  2         5  
  2         66  
14 2     2   357  
  2         4  
  2         908  
15             our $VERSION = version->new(1.1.20);
16             our $workflow = App::Git::Workflow->new;
17             my ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
18             our %option;
19             our %p2u_extra;
20              
21             my ($self) = @_;
22              
23 1     1 1 2 %option = (
24             exclude => [],
25 1         3 );
26             get_options(
27             \%option,
28 1 50       6 'remote|r',
29             'all|a',
30             'exclude|e=s@',
31             'exclude_file|exclude-file|f=s',
32             'max|n=i',
33             'reverse|R',
34             ) or return;
35              
36             # get the list of branches to look at
37             my $max = 0;
38             my @branches = $workflow->branches($option{remote} ? 'remote' : $option{all} ? 'both' : undef );
39 1         2 my @excludes = @{ $option{exclude} };
40 1 50       7 my ($total, $deleted) = (0, 0);
    50          
41 1         2  
  1         2  
42 1         2 if ($option{exclude_file}) {
43             for my $exclude ($workflow->slurp($option{exclude_file})) {
44 1 50       3 chomp $exclude;
45 0         0 next if !$exclude;
46 0         0 next if $exclude =~ /^\s*(?:[#].*)$/xms;
47 0 0       0 push @excludes, $exclude;
48 0 0       0 }
49 0         0 }
50              
51             my @found;
52             BRANCH:
53 1         1 for my $branch (@branches) {
54             # skip master branches
55 1         2 next BRANCH if grep {$branch =~ /$_/} @excludes;
56              
57 0 0       0 # get branch details
  0         0  
58             push @found, $workflow->commit_details($branch, branches => 0);
59             }
60 0         0  
61             for (@found) {
62             $max = length $_->{name} if length $_->{name} > $max;
63 1         8 }
64 0 0       0  
65             my $count = 0;
66             if ( $option{reverse} ) {
67 1         3 @found = reverse sort {$a->{time} <=> $b->{time}} @found;
68 1 50       3 }
69 0         0 else {
  0         0  
70             @found = sort {$a->{time} <=> $b->{time}} @found;
71             }
72 1         3  
  0         0  
73             for my $details (@found) {
74             last if $option{max} && $count++ >= $option{max};
75 1         2 printf "%-${max}s %s\n", $details->{name}, scalar localtime $details->{time};
76 0 0 0     0 }
77 0         0  
78             return;
79             }
80 1         3  
81             1;
82              
83              
84             =head1 NAME
85              
86             git-branches - lists branches with dates of last commits
87              
88             =head1 VERSION
89              
90             This documentation refers to git-branches version 1.1.20
91              
92             =head1 SYNOPSIS
93              
94             git-branches [option]
95              
96             OPTIONS:
97             -r --remote Only remote branches (defaults to local branches)
98             -a --all All branches
99             -e --exclude[=]regex
100             Regular expression to exclude specific branches from deletion.
101             You can specify --exclude multiple times for more control.
102             --exclude-file[=]file
103             A file of exclude regular expressions, blank lines and lines
104             starting with a hash (#) are ignored.
105             -n --max[=]int
106             Maximum number of branches to show
107             -R --reverse Reverse the display order of branches
108              
109             -v --verbose Show more detailed option
110             --version Prints the version information
111             --help Prints this help information
112             --man Prints the full documentation for git-branches
113              
114             =head1 DESCRIPTION
115              
116             C<git-branches> aims to show details about all branches ordered by commit date.
117              
118             =head1 SUBROUTINES/METHODS
119              
120             =head2 C<run ()>
121              
122             Executes the git workflow command
123              
124             =head1 DIAGNOSTICS
125              
126             =head1 CONFIGURATION AND ENVIRONMENT
127              
128             =head1 DEPENDENCIES
129              
130             =head1 INCOMPATIBILITIES
131              
132             =head1 BUGS AND LIMITATIONS
133              
134             There are no known bugs in this module.
135              
136             Please report problems to Ivan Wills (ivan.wills@gmail.com).
137              
138             Patches are welcome.
139              
140             =head1 AUTHOR
141              
142             Ivan Wills - (ivan.wills@gmail.com)
143              
144             =head1 LICENSE AND COPYRIGHT
145              
146             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
147             All rights reserved.
148              
149             This module is free software; you can redistribute it and/or modify it under
150             the same terms as Perl itself. See L<perlartistic>. This program is
151             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
152             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
153             PARTICULAR PURPOSE.
154              
155             =cut