blib/lib/Dist/Zilla/Plugin/Git/Commit.pm

filter: Statementstmt 100% 73 / 73 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 50.0% 1 / 2 totaltotal 95.0% 96 / 101 CC 9 SCAR 12.4
CC
9
Cov
95%
after_release
8.1
__ANON__
2.0
BEGIN
1.0
CRAP 3.4
« blib/lib/Dist/Zilla/Plugin/Git/Push.pm ↑ Summary blib/lib/Dist/Zilla/Role/Git/StringFormatter.pm »
1 #
2 # This file is part of Dist-Zilla-Plugin-Git
3 #
4 # This software is copyright (c) 2009 by Jerome Quelin.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 10 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package Dist::Zilla::Plugin::Git::Commit;
14 # ABSTRACT: Commit dirty files
15  
16 10 our $VERSION = '2.052';
17  
18 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use File::Temp qw{ tempfile };
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 10 ▶use Types::Standard qw(Str ArrayRef Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 ▶use Types::Path::Tiny 'Path';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 10 ▶use Path::Tiny 0.048 qw(); # subsumes
Subroutine BEGIN: called CC=1 SCAR=0.0
24 10 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 10 with 'Dist::Zilla::Role::AfterRelease',
27 'Dist::Zilla::Role::Git::Repo';
28 10 with 'Dist::Zilla::Role::Git::DirtyFiles';
29 10 with 'Dist::Zilla::Role::Git::StringFormatter';
30 10 with 'Dist::Zilla::Role::GitConfig';
31  
32 2 ▶sub _git_config_mapping { +{
Subroutine _git_config_mapping: called CC=1 SCAR=0.0
33 2 changelog => '%{changelog}s',
34 } }
35  
36 # -- attributes
37  
38 10 has commit_msg => ( is => 'ro', isa=>Str, default => 'v%V%n%n%c' );
39 21 ▶has add_files_in => ( is => 'ro', isa=> ArrayRef[Path], coerce => 1, default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
40 10 has signoff => ( is => 'ro', isa => Bool, default => 0 );
41  
42  
43 # -- public methods
44  
45 14 ▶sub mvp_multivalue_args { qw( add_files_in ) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
46  
47 around dump_config => sub
48 11 ▶{
Subroutine __ANON__: called CC=2 SCAR=7.0
49 11 my $orig = shift;
50 11 my $self = shift;
51  
52 11 my $config = $self->$orig;
53  
54 $config->{+__PACKAGE__} = {
55 commit_msg => $self->commit_msg,
56 11 ▶ add_files_in => [ sort @{ $self->add_files_in } ],
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ne __PACKAGE__ ? : 0 11 11
57 signoff => $self->signoff,
58 blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
59 };
60  
61 11 return $config;
62 10 };
63  
64 9 ▶sub after_release {
Subroutine after_release: called CC=8 SCAR=20.9
Pod undocumented
65 9 my $self = shift;
66  
67 9 my $git = $self->git;
68 9 my @output;
69  
70 # check if there are dirty files that need to be committed.
71 # at this time, we know that only those 2 files may remain modified,
72 # otherwise before_release would have failed, ending the release
73 # process.
74 9 @output = sort { lc $a cmp lc $b } $self->list_dirty_files($git, 1);
75  
76 # add any other untracked files to the commit list
77 9 ▶ if ( @{ $self->add_files_in } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->add_files_in;}) 1 8 9
78 1 my @untracked_files = $git->ls_files( { others=>1, 'exclude-standard'=>1 } );
79 1 foreach my $f ( @untracked_files ) {
80 1 foreach my $path ( @{ $self->add_files_in } ) {
81 1 ▶ if ( Path::Tiny::path( $path )->subsumes( $f ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Path::Tiny::path($path)->subsumes($f)) 1 0 1
82 1 push( @output, $f );
83 1 last;
84 }
85 }
86 }
87 }
88  
89 # if nothing to commit, we're done!
90 9 ▶ return unless @output;
Branch: 1 branch
BranchTrueFalseTotal
unless @output 0 9 9
91  
92 # write commit message in a temp file
93 9 my ($fh, $filename) = tempfile( getcwd . '/DZP-git.XXXX', UNLINK => 1 );
94 9 ▶ binmode $fh, ':utf8' unless Dist::Zilla->VERSION < 5;
Branch: 1 branch
BranchTrueFalseTotal
unless "Dist::Zilla"->VERSION < 5 9 0 9
95 9 print $fh $self->get_commit_message;
96 9 close $fh;
97  
98 # commit the files in git
99 9 $git->add( @output );
100 9 $self->log_debug($_) for $git->commit( { signoff => $self->signoff,
101 file => $filename } );
102 9 $self->log("Committed @output");
103 }
104  
105  
106 #pod =method get_commit_message
107 #pod
108 #pod This method returns the commit message. The default implementation
109 #pod reads the Changes file to get the list of changes in the just-released version.
110 #pod
111 #pod =cut
112  
113 19 ▶sub get_commit_message {
Subroutine get_commit_message: called CC=1 SCAR=0.0
Pod documented
114 19 my $self = shift;
115  
116 19 return $self->_format_string($self->commit_msg);
117 } # end get_commit_message
118  
119 10 __PACKAGE__->meta->make_immutable;
120 10 1;
121  
122 __END__
« blib/lib/Dist/Zilla/Plugin/Git/Push.pm ↑ Summary blib/lib/Dist/Zilla/Role/Git/StringFormatter.pm »