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

filter: Statementstmt 94.9% 56 / 59 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 3 totaltotal 87.7% 79 / 90 CC 12 SCAR 12.5
CC
12
Cov
89%
before_release
6.1
after_release
5.1
__ANON__
3.1
CRAP 3.5
« blib/lib/Dist/Zilla/Plugin/Git/NextVersion.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Git/Commit.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 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 package Dist::Zilla::Plugin::Git::Push;
14 # ABSTRACT: Push current branch
15  
16 3 our $VERSION = '2.052';
17  
18 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Types::Standard qw{ ArrayRef Str Bool };
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 with 'Dist::Zilla::Role::BeforeRelease',
24 'Dist::Zilla::Role::AfterRelease';
25 3 with 'Dist::Zilla::Role::Git::Repo',
26 'Dist::Zilla::Role::GitConfig';
27  
28 7 ▶sub mvp_multivalue_args { qw(push_to) }
Subroutine mvp_multivalue_args: called CC=1 SCAR=0.0
Pod undocumented
29  
30 2 ▶sub _git_config_mapping { +{
Subroutine _git_config_mapping: called CC=1 SCAR=0.0
31 2 push_to => '%{remote}s %{local_branch}s:%{remote_branch}s',
32 } }
33  
34 # -- attributes
35  
36 3 has remotes_must_exist => ( is => 'ro', isa=>Bool, default=>1 );
37  
38 has push_to => (
39 is => 'ro',
40 isa => ArrayRef[Str],
41 lazy => 1,
42 1 ▶ default => sub { [ qw(origin) ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 3 );
44  
45 around dump_config => sub
46 5 ▶{
Subroutine __ANON__: called CC=3 SCAR=11.3
47 5 my $orig = shift;
48 5 my $self = shift;
49  
50 5 my $config = $self->$orig;
51  
52 5 ▶ $config->{+__PACKAGE__} = {
Branch: 2 branches
BranchTrueFalseTotal
$self->remotes_must_exist ? : 5 0 5
builtin::blessed($self) ne __PACKAGE__ ? : 0 5 5
53 push_to => $self->push_to,
54 remotes_must_exist => $self->remotes_must_exist ? 1 : 0,
55 blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
56 };
57  
58 5 return $config;
59 3 };
60  
61 5 ▶sub before_release {
Subroutine before_release: called CC=6 SCAR=18.1
Pod undocumented
62 5 my $self = shift;
63  
64 5 ▶ return unless $self->remotes_must_exist;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->remotes_must_exist 0 5 5
65  
66 5 my %valid_remote = map { $_ => 1 } $self->git->remote;
67 5 my @bad_remotes;
68  
69 # Make sure the remotes we'll be pushing to exist
70 5 for my $remote_spec ( @{ $self->push_to } ) {
71 7 (my $remote = $remote_spec) =~ s/\s.*//s; # Discard branch (if specified)
72 7 ▶ if ($remote =~ m![:/]!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remote =~ m[[:/]]) { } 0 7 7
73 # Appears to be a URL or path, don't check it
74 0 $self->log("Will push to $remote (not checked)");
75 } else {
76 # Named remotes must exist
77 7 ▶ push @bad_remotes, $remote unless $valid_remote{$remote};
Branch: 1 branch
BranchTrueFalseTotal
unless $valid_remote{$remote} 2 5 7
78 }
79 }
80  
81 5 ▶ $self->log_fatal("These remotes do not exist: @bad_remotes")
Branch: 1 branch
BranchTrueFalseTotal
if @bad_remotes 2 3 5
82 if @bad_remotes;
83 }
84  
85  
86 3 ▶sub after_release {
Subroutine after_release: called CC=5 SCAR=16.3
Pod undocumented
87 3 my $self = shift;
88 3 my $git = $self->git;
89  
90 # requires git 2.4.1; see "git push --follow-tags"
91 3 $git->config('push.followTags', 'true');
92  
93 # push everything on remote branch
94 3 for my $remote ( @{ $self->push_to } ) {
95 4 $self->log("pushing to $remote");
96 4 my @remote = split(/\s+/,$remote);
97 4 ▶ if (@remote == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@remote == 1) 3 1 4
98 # Newer versions of Git may not push the current branch automatically.
99 # Append the current branch since the remote didn't specify a branch.
100 3 my $branch = $self->current_git_branch;
101 3 ▶ unless (defined $branch) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $branch) 0 3 3
102 0 $self->log("skipped push to @remote (can't determine branch to push)");
103 0 next;
104 }
105 3 push @remote, $branch;
106 }
107 # push.followTags is set, so this also pushes the release tag that was
108 # likely just created by [Git::Tag]
109 4 $self->log_debug($_) for $git->push( @remote );
110 }
111 }
112  
113 3 __PACKAGE__->meta->make_immutable;
114 3 1;
115  
116 __END__
« blib/lib/Dist/Zilla/Plugin/Git/NextVersion.pm ↑ Summary blib/lib/Dist/Zilla/Plugin/Git/Commit.pm »