| 1 | package App::gh::Command::Clone; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(App::gh::Command); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use App::gh::Utils qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | generate_repo_uri | ||||||||||||||||||||||||||||
| 8 | build_git_clone_command | ||||||||||||||||||||||||||||
| 9 | run_git_fetch | ||||||||||||||||||||||||||||
| 10 | 1 | ); | |||||||||||||||||||||||||||
| 11 | 1 | ▶ | use App::gh; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | App::gh::Command::Clone - clone repository | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | balh | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | -q, --quiet | ||||||||||||||||||||||||||||
| 24 | --verbose | ||||||||||||||||||||||||||||
| 25 | --ssh | ||||||||||||||||||||||||||||
| 26 | --http | ||||||||||||||||||||||||||||
| 27 | --https | ||||||||||||||||||||||||||||
| 28 | --git|ro | ||||||||||||||||||||||||||||
| 29 | -k, --forks also fetch forks. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Git Options: | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | -b | --branch clone specific branch. | ||||||||||||||||||||||||||||
| 34 | --origin | ||||||||||||||||||||||||||||
| 35 | --recursive, --recurse-submodules | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | After the clone is created, initialize all submodules within, using their default settings. | ||||||||||||||||||||||||||||
| 38 | This is equivalent to running git submodule update --init --recursive immediately after the | ||||||||||||||||||||||||||||
| 39 | clone is finished. This option is ignored if the cloned repository does not have a | ||||||||||||||||||||||||||||
| 40 | worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or --mirror is given) | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | See `git help clone` | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub options { ( | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | "verbose" => "verbose", | |||||||||||||||||||||||||||
| 48 | "ssh" => "protocol_ssh", # git@github.com:c9s/repo.git | ||||||||||||||||||||||||||||
| 49 | "http" => "protocol_http", # http://github.com/c9s/repo.git | ||||||||||||||||||||||||||||
| 50 | "https" => "protocol_https", # https://github.com/c9s/repo.git | ||||||||||||||||||||||||||||
| 51 | "git|ro" => "protocol_git", # git://github.com/c9s/repo.git | ||||||||||||||||||||||||||||
| 52 | "k|forks|fork" => 'with_fork', | ||||||||||||||||||||||||||||
| 53 | "b|bare" => "bare", | ||||||||||||||||||||||||||||
| 54 | "b|branch=s" => "branch", | ||||||||||||||||||||||||||||
| 55 | "mirror" => "mirror", | ||||||||||||||||||||||||||||
| 56 | "recursive" => "recursive", | ||||||||||||||||||||||||||||
| 57 | "origin" => "origin", | ||||||||||||||||||||||||||||
| 58 | ) } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 64 | 0 | my $repo; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | if( $user =~ /\// ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ($user, $repo) = split /\//, $user; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | $repo = shift; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | unless( $user && $repo ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user and $repo
MC/DC0%0/2
$user and $repo
$user
$repo
Truth table0%0/3
A and B
A= $userB= $repo
| |||||||||||||||||||||||||||||
| 72 | 0 | die "Usage: gh clone [user] [repo]\n"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $uri = generate_repo_uri($user, $repo, $self); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @command = build_git_clone_command($uri,$self); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | print 'Cloning ', $uri, "...\n"; | |||||||||||||||||||||||||||
| 80 | 0 | my $cmd = join ' ', @command; | |||||||||||||||||||||||||||
| 81 | 0 | qx($cmd); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # fetch forks | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if( $self->{with_fork} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | my $dirname = basename($uri,'.git'); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # get networks | ||||||||||||||||||||||||||||
| 88 | 0 | my $repos = App::gh->github->repos->set_default_user_repo($user,$repo); | |||||||||||||||||||||||||||
| 89 | 0 | my @forks = $repos->forks; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if( @forks ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | print "Found " , scalar(@forks) , " forks to fetch...\n"; | |||||||||||||||||||||||||||
| 92 | 0 | chdir $dirname; | |||||||||||||||||||||||||||
| 93 | 0 | for my $fork ( @forks ) { | |||||||||||||||||||||||||||
| 94 | my ($full_name,$clone_url,$login) = | ||||||||||||||||||||||||||||
| 95 | 0 | ($fork->{full_name},$fork->{clone_url},$fork->{owner}->{login}); | |||||||||||||||||||||||||||
| 96 | 0 | print "===> Adding remote $login => $clone_url\n"; | |||||||||||||||||||||||||||
| 97 | 0 | qx(git remote add $login $clone_url); | |||||||||||||||||||||||||||
| 98 | 0 | print "===> Fetching fork $full_name...\n"; | |||||||||||||||||||||||||||
| 99 | 0 | run_git_fetch $login; | |||||||||||||||||||||||||||
| 100 | 0 | qx(git fetch $login); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | 1; | |||||||||||||||||||||||||||