| File: | blib/lib/Git/ReleaseRepo/Command/update.pm |
| Coverage: | 76.9% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Git::ReleaseRepo::Command::update; | ||||||
| 2 | # ABSTRACT: Update a deployed release repository | ||||||
| 3 | |||||||
| 4 | 2 2 2 | 101730 4 20 | use Moose; | ||||
| 5 | extends 'Git::ReleaseRepo::Command'; | ||||||
| 6 | |||||||
| 7 | override usage_desc => sub { | ||||||
| 8 | my ( $self ) = @_; | ||||||
| 9 | return super(); | ||||||
| 10 | }; | ||||||
| 11 | |||||||
| 12 | sub description { | ||||||
| 13 | 0 | 1 | 0 | return 'Update a deployed release repository'; | |||
| 14 | } | ||||||
| 15 | |||||||
| 16 | sub validate_args { | ||||||
| 17 | 2 | 1 | 1170 | my ( $self, $opt, $args ) = @_; | |||
| 18 | 2 | 9 | return $self->usage_error( "Too many arguments" ) if ( @$args > 0 ); | ||||
| 19 | } | ||||||
| 20 | |||||||
| 21 | around opt_spec => sub { | ||||||
| 22 | my ( $orig, $self ) = @_; | ||||||
| 23 | return ( | ||||||
| 24 | $self->$orig, | ||||||
| 25 | [ 'branch=s' => 'Specify the release branch to deploy. Defaults to the latest release branch.' ], | ||||||
| 26 | [ 'master' => 'Deploy the "master" version of the repository and all submodules, for testing.' ], | ||||||
| 27 | ); | ||||||
| 28 | }; | ||||||
| 29 | |||||||
| 30 | augment execute => sub { | ||||||
| 31 | my ( $self, $opt, $args ) = @_; | ||||||
| 32 | my $repo = $self->git; | ||||||
| 33 | my $branch = $opt->{master} ? "master" | ||||||
| 34 | : $opt->{branch} ? $opt->{branch} | ||||||
| 35 | : $self->config->{track}; | ||||||
| 36 | my $version = $opt->{master} ? "master" | ||||||
| 37 | : $repo->latest_version( $branch ); | ||||||
| 38 | $repo->checkout( $version ); | ||||||
| 39 | if ( $opt->{master} ) { | ||||||
| 40 | my $cmd = $repo->command( submodule => 'foreach', 'git checkout master && git pull origin master' ); | ||||||
| 41 | my @stderr = readline $cmd->stderr; | ||||||
| 42 | my @stdout = readline $cmd->stdout; | ||||||
| 43 | $cmd->close; | ||||||
| 44 | if ( $cmd->exit != 0 ) { | ||||||
| 45 | die "Could not checkout master\nEXIT: " . $cmd->exit . "\nSTDERR: " . ( join "\n", @stderr ) | ||||||
| 46 | . "\nSTDOUT: " . ( join "\n", @stdout ); | ||||||
| 47 | } | ||||||
| 48 | } | ||||||
| 49 | }; | ||||||
| 50 | |||||||
| 51 | 1; | ||||||