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.337';
4             # ABSTRACT: clone a remote repo and add it to your config
5 15     15   9836 use 5.014;
  15         86  
6              
7 15     15   105 use Cwd;
  15         41  
  15         1160  
8 15     15   127 use Path::Tiny;
  15         86  
  15         879  
9 15     15   133 use IO::Prompt::Simple;
  15         42  
  15         967  
10 15     15   132 use Types::Standard -types;
  15         51  
  15         286  
11              
12 15     15   70999 use App::GitGot -command;
  15         37  
  15         129  
13 15     15   5471 use App::GitGot::Repo::Git;
  15         44  
  15         451  
14              
15 15     15   88 use Moo;
  15         37  
  15         93  
16             extends 'App::GitGot::Command';
17 15     15   5855 use namespace::autoclean;
  15         57  
  15         129  
18              
19             sub options {
20 2     2 0 195 my( $class , $app ) = @_;
21             return (
22 2         20 [ 'defaults|D' => 'use the default choices for all prompts' ] ,
23             [ 'recursive|r' => 'clone submodules recursively' => { default => 0 } ],
24             );
25             }
26              
27 2     2   10 sub _use_io_page { 0 }
28              
29             sub _execute {
30 2     2   6 my ( $self, $opt, $args ) = @_;
31              
32 2         5 my ( $repo , $path ) = @$args;
33              
34 2   33     10 $repo // ( say STDERR 'ERROR: Need the URL to clone!' and exit(1) );
      66        
35              
36 1 50 0     17 my $cwd = getcwd
37             or( say STDERR "ERROR: Couldn't determine path" and exit(1) );
38              
39 1         6 my $name = path( $repo )->basename;
40 1         78 $name =~ s/.git$//;
41              
42 1   33     12 $path //= "$cwd/$name";
43 1         3 $path = path( $path )->absolute;
44              
45 1         64 my $tags;
46              
47 1 50       10 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         33 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       113 $new_entry->{tags} = $tags if $tags;
64              
65 1 50       32 say "Cloning into '$path'..." unless $self->quiet;
66 1         44 $new_entry->clone(
67             { recursive => $self->opt->recursive },
68             $repo , $path
69             );
70              
71 1         27 $self->add_repo( $new_entry );
72 1         103 $self->write_config;
73             }
74              
75             1;
76              
77             __END__