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

filter: Statementstmt 50.0% 26 / 52 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 1 totaltotal 45.9% 34 / 74 CC 5 SCAR 22.8
CC
5
Cov
43%
after_mint
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 9.8
↑ Summary
1 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Dist::Zilla::Plugin::Git::PushInitial;
3 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $Dist::Zilla::Plugin::Git::PushInitial::AUTHORITY = 'cpan:RKITOVER';
5 }
6 {
7 1 $Dist::Zilla::Plugin::Git::PushInitial::VERSION = '0.02';
8 }
9  
10 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MooseX::Types::Moose qw/Str Undef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Git::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec::Functions qw/catfile catdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 with 'Dist::Zilla::Role::AfterMint';
18  
19 =encoding UTF-8
20  
21 =head1 NAME
22  
23 Dist::Zilla::Plugin::Git::PushInitial - do initial git push from your minting profile
24  
25 =head1 SYNOPSIS
26  
27 In your profile.ini:
28  
29 [Git::Init]
30  
31 [GitHub::Create]
32 repo = {{ lc $dist->name }}
33 prompt = 1
34  
35 [Git::PushInitial]
36 remote = origin # default
37  
38 =head1 DESCRIPTION
39  
40 This module is only of interest to authors of L<Dist::Zilla> minting profiles.
41  
42 After minting a new dist with L<Git::Init|Dist::Zilla::Plugin::Git::Init> and
43 setting remote information with e.g.
44 L<GitHub::Create|Dist::Zilla::Plugin::GitHub::Create>, if C<push.default> is
45 not configured or set at the default value (C<tracking>), or an older git is
46 being used, it is necessary to create the branch on the remote before a simple
47 C<git push>, done by e.g. L<Git::Push|Dist::Zilla::Plugin::Git::Push> will work
48 on C<dzil release>.
49  
50 Using this plugin in your minting profile should save the users of your minting
51 profile the step of doing a manual push, regardless of their git config. They
52 can just commit and do a C<dzil release>, assuming they are using
53 L<Git::Push|Dist::Zilla::Plugin::Git::Push> in their dist.ini.
54  
55 It runs this command:
56  
57 git push <remote> <current-branch>
58  
59 remote defaults to 'origin' but can be specified as a parameter to this plugin.
60  
61 =head1 PARAMETERS
62  
63 =head2 remote
64  
65 The remote to push to, default is C<origin>.
66  
67 =cut
68  
69 1 has remote => (is => 'ro', isa => Str|Undef, default => 'origin');
70  
71 0 ▶sub after_mint {
Subroutine after_mint: not called CC=5 SCAR=34.0
Pod undocumented
72 0 my ($self, $opts) = @_;
73  
74 0 my $root = $opts->{mint_root};
75  
76 0 ▶ if (not -e catdir($root, '.git')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e catdir($root, ".git")) 0 0 0
77 0 $self->log('Not a git repo, bailing out');
78 0 return;
79 }
80  
81 0 my $git = Git::Wrapper->new($root);
82  
83 0 ▶ my (@remotes) = try { $git->remote };
Subroutine __ANON__: not called CC=1 SCAR=6.9
84  
85 0 ▶ if (not (grep $_ eq $self->remote, @remotes)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep(($_ eq $self->remote), @remotes)) 0 0 0
86 0 $self->log("Remote '".$self->remote."' does not exist, bailing out");
87 0 return;
88 }
89  
90 0 ▶ my ($branch) = try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 $git->rev_parse({ abbrev_ref => 1, symbolic_full_name => 1 }, 'HEAD')
92 0 };
93  
94 0 ▶ if (not $branch) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($branch) 0 0 0
95 0 $self->log('No branch found, bailing out');
96 0 return;
97 }
98  
99 0 my $error;
100  
101 0 ▶ my $pushed = try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 $git->push($self->remote, $branch); 1;
103 }
104 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 $error = $_; 0;
106 0 };
107  
108 0 ▶ if (not $pushed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pushed) 0 0 0
109 0 $self->log("Error pushing branch '$branch': $error");
110 0 return;
111 }
112  
113 0 $self->log("Pushed '$branch' to '".$self->remote."' successfully.");
114 }
115  
116 =head1 SEE ALSO
117  
118 =over 4
119  
120 =item * L<Minting Profiles Tutorial|http://dzil.org/tutorial/minting-profile.html>
121  
122 =item * L<Dist::Zilla::Plugin::Git::Init>
123  
124 =item * L<Dist::Zilla::Plugin::GitHub::Create>
125  
126 =item * L<Dist::Zilla::Plugin::Git::Push>
127  
128 =item * L<Dist::Zilla::MintingProfile::Author::Caelum>
129  
130 =back
131  
132 =head1 ACKNOWLEDGEMENTS
133  
134 Some code/ideas stolen from Alessandro Ghedini's
135 L<Dist::Zilla::Plugin::GitHub::Create>.
136  
137 =head1 AUTHOR
138  
139 Rafael Kitover <rkitover@cpan.org>
140  
141 =cut
142  
143 1 __PACKAGE__; # End of Dist::Zilla::Plugin::Git::PushInitial
↑ Summary