File Coverage

blib/lib/App/GitGot/Command/clone.pm
Criterion Covered Total %
statement 45 51 88.2
branch 4 10 40.0
condition 4 12 33.3
subroutine 12 12 100.0
pod 0 1 0.0
total 65 86 75.5


line stmt bran cond sub pod time code
1             package App::GitGot::Command::clone;
2             our $AUTHORITY = 'cpan:GENEHACK';
3             $App::GitGot::Command::clone::VERSION = '1.336';
4             # ABSTRACT: clone a remote repo and add it to your config
5 15     15   7517 use 5.014;
  15         49  
6              
7 15     15   85 use Cwd;
  15         31  
  15         807  
8 15     15   89 use Path::Tiny;
  15         39  
  15         589  
9 15     15   90 use IO::Prompt::Simple;
  15         33  
  15         747  
10 15     15   77 use Types::Standard -types;
  15         26  
  15         182  
11              
12 15     15   56173 use App::GitGot -command;
  15         34  
  15         103  
13 15     15   4040 use App::GitGot::Repo::Git;
  15         32  
  15         353  
14              
15 15     15   73 use Moo;
  15         33  
  15         77  
16             extends 'App::GitGot::Command';
17 15     15   4657 use namespace::autoclean;
  15         29  
  15         80  
18              
19             sub options {
20 2     2 0 161 my( $class , $app ) = @_;
21             return (
22 2         16 [ 'defaults|D' => 'use the default choices for all prompts' ] ,
23             );
24             }
25              
26 2     2   7 sub _use_io_page { 0 }
27              
28             sub _execute {
29 2     2   4 my ( $self, $opt, $args ) = @_;
30              
31 2         5 my ( $repo , $path ) = @$args;
32              
33 2   33     10 $repo // ( say STDERR 'ERROR: Need the URL to clone!' and exit(1) );
      66        
34              
35 1 50 0     14 my $cwd = getcwd
36             or( say STDERR "ERROR: Couldn't determine path" and exit(1) );
37              
38 1         4 my $name = path( $repo )->basename;
39 1         66 $name =~ s/.git$//;
40              
41 1   33     8 $path //= "$cwd/$name";
42 1         3 $path = path( $path )->absolute;
43              
44 1         48 my $tags;
45              
46 1 50       8 unless ( $self->opt->defaults ) {
47 0         0 $name = prompt( 'Name: ' , $name );
48 0         0 while() {
49 0         0 $path = prompt( 'Path: ' , $path );
50 0 0       0 last if not path($path)->exists;
51 0         0 say "can't clone into '$path': directory already exists";
52             }
53 0         0 $tags = prompt( 'Tags: ' , $tags );
54             }
55              
56 1         28 my $new_entry = App::GitGot::Repo::Git->new({ entry => {
57             repo => $repo,
58             name => $name,
59             type => 'git',
60             path => $path,
61             }});
62 1 50       89 $new_entry->{tags} = $tags if $tags;
63              
64 1 50       21 say "Cloning into '$path'..." unless $self->quiet;
65 1         45 $new_entry->clone( $repo , $path );
66              
67 1         21 $self->add_repo( $new_entry );
68 1         91 $self->write_config;
69             }
70              
71             1;
72              
73             __END__