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.339';
4             # ABSTRACT: clone a remote repo and add it to your config
5 15     15   9822 use 5.014;
  15         95  
6              
7 15     15   99 use Cwd;
  15         51  
  15         1201  
8 15     15   174 use Path::Tiny;
  15         47  
  15         942  
9 15     15   107 use IO::Prompt::Simple;
  15         36  
  15         994  
10 15     15   124 use Types::Standard -types;
  15         40  
  15         300  
11              
12 15     15   74133 use App::GitGot -command;
  15         79  
  15         136  
13 15     15   5683 use App::GitGot::Repo::Git;
  15         45  
  15         477  
14              
15 15     15   93 use Moo;
  15         39  
  15         115  
16             extends 'App::GitGot::Command';
17 15     15   6155 use namespace::autoclean;
  15         47  
  15         132  
18              
19             sub options {
20 2     2 0 238 my( $class , $app ) = @_;
21             return (
22 2         24 [ 'defaults|D' => 'use the default choices for all prompts' ] ,
23             [ 'recursive|r' => 'clone submodules recursively' => { default => 0 } ],
24             );
25             }
26              
27 2     2   11 sub _use_io_page { 0 }
28              
29             sub _execute {
30 2     2   7 my ( $self, $opt, $args ) = @_;
31              
32 2         5 my ( $repo , $path ) = @$args;
33              
34 2   33     15 $repo // ( say STDERR 'ERROR: Need the URL to clone!' and exit(1) );
      66        
35              
36 1 50 0     16 my $cwd = getcwd
37             or( say STDERR "ERROR: Couldn't determine path" and exit(1) );
38              
39 1         7 my $name = path( $repo )->basename;
40 1         142 $name =~ s/.git$//;
41              
42 1   33     10 $path //= "$cwd/$name";
43 1         4 $path = path( $path )->absolute;
44              
45 1         66 my $tags;
46              
47 1 50       11 unless ( $self->opt->defaults ) {
48 0         0 $name = prompt( 'Name: ' , $name );
49 0         0 while() {
50 0         0 $path = prompt( 'Path: ' , $path );
51 0 0       0 last if not path($path)->exists;
52 0         0 say "can't clone into '$path': directory already exists";
53             }
54 0         0 $tags = prompt( 'Tags: ' , $tags );
55             }
56              
57 1         27 my $new_entry = App::GitGot::Repo::Git->new({ entry => {
58             repo => $repo,
59             name => $name,
60             type => 'git',
61             path => $path,
62             }});
63 1 50       111 $new_entry->{tags} = $tags if $tags;
64              
65 1 50       25 say "Cloning into '$path'..." unless $self->quiet;
66 1         43 $new_entry->clone(
67             { recursive => $self->opt->recursive },
68             $repo , $path
69             );
70              
71 1         27 $self->add_repo( $new_entry );
72 1         89 $self->write_config;
73             }
74              
75             1;
76              
77             __END__