File Coverage

blib/lib/App/Git/Workflow/Command/Touch.pm
Criterion Covered Total %
statement 42 53 79.2
branch 2 8 25.0
condition 1 2 50.0
subroutine 12 12 100.0
pod 1 2 50.0
total 58 77 75.3


line stmt bran cond sub pod time code
1              
2             # Created on: 2014-03-11 20:58:59
3             # Create by: Ivan Wills
4             # $Id$
5             # $Revision$, $HeadURL$, $Date$
6             # $Revision$, $Source$, $Date$
7              
8             use strict;
9 2     2   84615 use warnings;
  2         13  
  2         50  
10 2     2   8 use version;
  2         5  
  2         40  
11 2     2   362 use English qw/ -no_match_vars /;
  2         1568  
  2         10  
12 2     2   535 use DateTime::Format::HTTP;
  2         2942  
  2         8  
13 2     2   990 use File::Touch;
  2         445824  
  2         61  
14 2     2   758 use Term::ANSIColor qw/colored/;
  2         28043  
  2         118  
15 2     2   570 use Path::Tiny;
  2         7005  
  2         820  
16 2     2   758  
  2         9888  
  2         103  
17             use App::Git::Workflow;
18 2     2   496 use App::Git::Workflow::Command qw/get_options/;
  2         6  
  2         75  
19 2     2   463  
  2         6  
  2         757  
20             our $VERSION = version->new(1.1.20);
21             our $workflow = App::Git::Workflow->new;
22             our ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
23             our %option;
24              
25             get_options( \%option, 'recurse|r!', 'commitish|c=s', );
26              
27 1     1 1 6 for my $file (@ARGV) {
28             git_touch($file);
29 1         2 }
30 1         4 }
31              
32             my ($file) = @_;
33             my $ref = $option{commitish} || 'HEAD';
34              
35 1     1 0 3 if ( -d $file ) {
36 1   50     5 my $max_time = 0;
37              
38 1 50       21 if ( !$option{recurse} ) {
39 0         0 return 0;
40             }
41 0 0       0 my @children = path($file)->children;
42 0         0 for my $child (@children) {
43             my $time = git_touch($child);
44 0         0 if ( $time > $max_time ) {
45 0         0 $max_time = $time;
46 0         0 }
47 0 0       0 }
48 0         0  
49             File::Touch->new( time => $max_time )->touch($file);
50             return $max_time;
51             }
52 0         0  
53 0         0 my ($log) = $workflow->git->log( '-n1', '--format=format:%ai', $file );
54              
55             if ( !$log ) {
56 1         7 return 0;
57             }
58 1 50       9  
59 0         0 my ( $date, $tz ) = $log =~ /^(.*)\s+([+-]\d{4})$/;
60             my $time = DateTime::Format::HTTP->parse_datetime( $date, $tz )->epoch;
61              
62 1         9 File::Touch->new( time => $time )->touch($file);
63 1         10  
64             return $time;
65 1         1045 }
66              
67 1         193 1;
68              
69              
70             =head1 NAME
71              
72             git-touch - Touch files to match the git change times
73              
74             =head1 VERSION
75              
76             This documentation refers to git-touch version 1.1.20
77              
78             =head1 SYNOPSIS
79              
80             git-touch [-r|--recurse] [(-c|--commitish) ref] file_or_dir
81              
82             OPTIONS:
83             -r --recurse
84             -c --commitish=[commitish]
85             Reference commit to get dates from (Default is current commit)
86              
87             -v --verbose Show more detailed option
88             --version Prints the version information
89             --help Prints this help information
90             --man Prints the full documentation for git-touch
91              
92             =head1 DESCRIPTION
93              
94             This will get the last changed time in the git history for a file and set
95             that time on the file.
96              
97             If the file is a directory and --recurse is specified then the directories
98             time will be set to the most rectent changed time for files with in it as
99             well as changing the times of those files.
100              
101             =head1 SUBROUTINES/METHODS
102              
103             =head2 C<run ()>
104              
105             Executes the git workflow command
106              
107             =head1 DIAGNOSTICS
108              
109             =head1 CONFIGURATION AND ENVIRONMENT
110              
111             =head1 DEPENDENCIES
112              
113             =head1 INCOMPATIBILITIES
114              
115             =head1 BUGS AND LIMITATIONS
116              
117             There are no known bugs in this module.
118              
119             Please report problems to Ivan Wills (ivan.wills@gmail.com).
120              
121             Patches are welcome.
122              
123             =head1 AUTHOR
124              
125             Ivan Wills - (ivan.wills@gmail.com)
126              
127             =head1 LICENSE AND COPYRIGHT
128              
129             Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
130             All rights reserved.
131              
132             This module is free software; you can redistribute it and/or modify it under
133             the same terms as Perl itself. See L<perlartistic>. This program is
134             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
135             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
136             PARTICULAR PURPOSE.
137              
138             =cut