| File: | blib/lib/Git/ReleaseRepo/Command/clone.pm |
| Coverage: | 94.9% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Git::ReleaseRepo::Command::clone; | ||||||
| 2 | # ABSTRACT: Clone an existing release repository | ||||||
| 3 | |||||||
| 4 | 2 2 2 | 1580 2 35 | use strict; | ||||
| 5 | 2 2 2 | 4 1 23 | use warnings; | ||||
| 6 | 2 2 2 | 4 2 5 | use Moose; | ||||
| 7 | extends 'Git::ReleaseRepo::CreateCommand'; | ||||||
| 8 | 2 2 2 | 7108 2 53 | use Cwd qw( abs_path ); | ||||
| 9 | 2 2 2 | 4 2 49 | use File::Spec::Functions qw( catdir catfile ); | ||||
| 10 | 2 2 2 | 4 1 45 | use File::HomeDir; | ||||
| 11 | 2 2 2 | 5 1 43 | use File::Path qw( make_path ); | ||||
| 12 | 2 2 2 | 5 1 42 | use File::Slurp qw( write_file ); | ||||
| 13 | 2 2 2 | 5 2 252 | use File::Basename qw( basename ); | ||||
| 14 | |||||||
| 15 | override usage_desc => sub { | ||||||
| 16 | my ( $self ) = @_; | ||||||
| 17 | return super() . " <repo_url> [<repo_name>]"; | ||||||
| 18 | }; | ||||||
| 19 | |||||||
| 20 | sub description { | ||||||
| 21 | 0 | 1 | return 'Clone an existing release repository'; | ||||
| 22 | } | ||||||
| 23 | |||||||
| 24 | augment execute => sub { | ||||||
| 25 | my ( $self, $opt, $args ) = @_; | ||||||
| 26 | # Clone the repo | ||||||
| 27 | my $repo_name = $args->[1] || $self->repo_name_from_url( $args->[0] ); | ||||||
| 28 | my $repo_dir = catdir( $self->repo_root, $repo_name ); | ||||||
| 29 | my $cmd = Git::Repository->command( clone => $args->[0], $repo_dir ); | ||||||
| 30 | my @stdout = readline $cmd->stdout; | ||||||
| 31 | my @stderr = readline $cmd->stderr; | ||||||
| 32 | $cmd->close; | ||||||
| 33 | print @stdout if @stdout; | ||||||
| 34 | print @stderr if @stderr; | ||||||
| 35 | |||||||
| 36 | # Set new default repo and configuration | ||||||
| 37 | $self->update_config( $opt, $repo_name, { default => 1 } ); | ||||||
| 38 | }; | ||||||
| 39 | |||||||
| 40 | 1; | ||||||