| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 3 |  | 7581 | use 5.008; | 
|  | 3 |  |  |  |  | 12 |  | 
| 10 | 3 |  |  | 3 |  | 24 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 85 |  | 
| 11 | 3 |  |  | 3 |  | 16 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 221 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | package Dist::Zilla::Plugin::Git::Push; | 
| 14 |  |  |  |  |  |  | # ABSTRACT: Push current branch | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our $VERSION = '2.046'; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 3 |  |  | 3 |  | 19 | use Moose; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 24 |  | 
| 19 | 3 |  |  | 3 |  | 19820 | use MooseX::Has::Sugar; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 35 |  | 
| 20 | 3 |  |  | 3 |  | 369 | use Types::Standard qw{ ArrayRef Str Bool }; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 34 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 3 |  |  | 3 |  | 2472 | use namespace::autoclean; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 29 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | with 'Dist::Zilla::Role::BeforeRelease', | 
| 25 |  |  |  |  |  |  | 'Dist::Zilla::Role::AfterRelease'; | 
| 26 |  |  |  |  |  |  | with 'Dist::Zilla::Role::Git::Repo', | 
| 27 |  |  |  |  |  |  | 'Dist::Zilla::Role::GitConfig'; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 7 |  |  | 7 | 0 | 3203 | sub mvp_multivalue_args { qw(push_to) } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub _git_config_mapping { +{ | 
| 32 | 2 |  |  | 2 |  | 265 | push_to => '%{remote}s %{local_branch}s:%{remote_branch}s', | 
| 33 |  |  |  |  |  |  | } } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # -- attributes | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | has remotes_must_exist => ( ro, isa=>Bool, default=>1 ); | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | has push_to => ( | 
| 40 |  |  |  |  |  |  | is   => 'ro', | 
| 41 |  |  |  |  |  |  | isa  => ArrayRef[Str], | 
| 42 |  |  |  |  |  |  | lazy => 1, | 
| 43 |  |  |  |  |  |  | default => sub { [ qw(origin) ] }, | 
| 44 |  |  |  |  |  |  | ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | around dump_config => sub | 
| 47 |  |  |  |  |  |  | { | 
| 48 |  |  |  |  |  |  | my $orig = shift; | 
| 49 |  |  |  |  |  |  | my $self = shift; | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | my $config = $self->$orig; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | $config->{+__PACKAGE__} = { | 
| 54 |  |  |  |  |  |  | push_to => $self->push_to, | 
| 55 |  |  |  |  |  |  | remotes_must_exist => $self->remotes_must_exist ? 1 : 0, | 
| 56 |  |  |  |  |  |  | blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (), | 
| 57 |  |  |  |  |  |  | }; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | return $config; | 
| 60 |  |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub before_release { | 
| 63 | 5 |  |  | 5 | 0 | 45226 | my $self = shift; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 5 | 50 |  |  |  | 638 | return unless $self->remotes_must_exist; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 5 |  |  |  |  | 133 | my %valid_remote = map { $_ => 1 } $self->git->remote; | 
|  | 6 |  |  |  |  | 38846 |  | 
| 68 | 5 |  |  |  |  | 64 | my @bad_remotes; | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | # Make sure the remotes we'll be pushing to exist | 
| 71 | 5 |  |  |  |  | 30 | for my $remote_spec ( @{ $self->push_to } ) { | 
|  | 5 |  |  |  |  | 587 |  | 
| 72 | 7 |  |  |  |  | 129 | (my $remote = $remote_spec) =~ s/\s.*//s; # Discard branch (if specified) | 
| 73 | 7 | 50 |  |  |  | 102 | if ($remote =~ m![:/]!) { | 
| 74 |  |  |  |  |  |  | # Appears to be a URL or path, don't check it | 
| 75 | 0 |  |  |  |  | 0 | $self->log("Will push to $remote (not checked)"); | 
| 76 |  |  |  |  |  |  | } else { | 
| 77 |  |  |  |  |  |  | # Named remotes must exist | 
| 78 | 7 | 100 |  |  |  | 80 | push @bad_remotes, $remote unless $valid_remote{$remote}; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 5 | 100 |  |  |  | 157 | $self->log_fatal("These remotes do not exist: @bad_remotes") | 
| 83 |  |  |  |  |  |  | if @bad_remotes; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub after_release { | 
| 88 | 3 |  |  | 3 | 0 | 2733 | my $self = shift; | 
| 89 | 3 |  |  |  |  | 72 | my $git  = $self->git; | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | # push everything on remote branch | 
| 92 | 3 |  |  |  |  | 31 | for my $remote ( @{ $self->push_to } ) { | 
|  | 3 |  |  |  |  | 156 |  | 
| 93 | 4 |  |  |  |  | 19183 | $self->log("pushing to $remote"); | 
| 94 | 4 |  |  |  |  | 1725 | my @remote = split(/\s+/,$remote); | 
| 95 | 4 | 100 |  |  |  | 52 | if (@remote == 1) { | 
| 96 |  |  |  |  |  |  | # Newer versions of Git may not push the current branch automatically. | 
| 97 |  |  |  |  |  |  | # Append the current branch since the remote didn't specify a branch. | 
| 98 | 3 |  |  |  |  | 147 | my $branch = $self->current_git_branch; | 
| 99 | 3 | 50 |  |  |  | 20 | unless (defined $branch) { | 
| 100 | 0 |  |  |  |  | 0 | $self->log("skipped push to @remote (can't determine branch to push)"); | 
| 101 | 0 |  |  |  |  | 0 | next; | 
| 102 |  |  |  |  |  |  | } | 
| 103 | 3 |  |  |  |  | 24 | push @remote, $branch; | 
| 104 |  |  |  |  |  |  | } | 
| 105 | 4 |  |  |  |  | 178 | $self->log_debug($_) for $git->push( @remote ); | 
| 106 | 4 |  |  |  |  | 107370 | $self->log_debug($_) for $git->push( { tags=>1 },  $remote[0] ); | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 111 |  |  |  |  |  |  | 1; | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | __END__ | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =pod | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =encoding UTF-8 | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head1 NAME | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Dist::Zilla::Plugin::Git::Push - Push current branch | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head1 VERSION | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | version 2.046 | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | In your F<dist.ini>: | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | [Git::Push] | 
| 132 |  |  |  |  |  |  | push_to = origin       ; this is the default | 
| 133 |  |  |  |  |  |  | push_to = origin HEAD:refs/heads/released ; also push to released branch | 
| 134 |  |  |  |  |  |  | remotes_must_exist = 1 ; this is the default | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | Once the release is done, this plugin will push the current git branch to | 
| 139 |  |  |  |  |  |  | the remote, with the associated tags. | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | The plugin accepts the following options: | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =over 4 | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item * | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | push_to - the name of the a remote to push to. The default is F<origin>. | 
| 148 |  |  |  |  |  |  | This may be specified multiple times to push to multiple repositories. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =item * | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | remotes_must_exist - if true, then Git::Push checks before a release | 
| 153 |  |  |  |  |  |  | to ensure that all named remotes specified in C<push_to> are | 
| 154 |  |  |  |  |  |  | configured in your repo.  The default is true.  Remotes specified as a | 
| 155 |  |  |  |  |  |  | URL or path are not checked, but will produce a | 
| 156 |  |  |  |  |  |  | C<Will push to %s (not checked)> message. | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =back | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =for Pod::Coverage after_release | 
| 161 |  |  |  |  |  |  | before_release | 
| 162 |  |  |  |  |  |  | mvp_multivalue_args | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head1 SUPPORT | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Git> | 
| 167 |  |  |  |  |  |  | (or L<bug-Dist-Zilla-Plugin-Git@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Git@rt.cpan.org>). | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | There is also a mailing list available for users of this distribution, at | 
| 170 |  |  |  |  |  |  | L<http://dzil.org/#mailing-list>. | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | There is also an irc channel available for users of this distribution, at | 
| 173 |  |  |  |  |  |  | L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>. | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =head1 AUTHOR | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | Jerome Quelin | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENCE | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | This software is copyright (c) 2009 by Jerome Quelin. | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 184 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =cut |