App-GitGot

 view release on metacpan or  search on metacpan

lib/App/GitGot/Command/fork.pm  view on Meta::CPAN


=head1 VERSION

version 1.339

=head1 SYNOPSIS

    # fork repo on GitHub, then clone repository and add to got config
    $ got fork github.com/owner/repo

    # fork repo on GitHub, add to got config, but do _not_ clone locally
    $ got fork -n github.com/owner/repo
    $ got fork --noclone github.com/owner/repo

=head1 AUTHOR

John SJ Anderson <john@genehack.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by John SJ Anderson.

t/02-add.t  view on Meta::CPAN


{
  my $result = test_app( 'App::GitGot' => [ 'add' ]);

  is   $result->stdout    , ''                              , 'empty STDOUT';
  like $result->stderr    , qr/Non-git repos not supported/ , 'expected error on STDERR';
  is   $result->exit_code , 1                               , 'exit with 1';
}

my $config = "$dir/gitgot";
file_not_exists_ok $config , 'no config';

Test::BASE::build_fake_git_repo();

{
  my $result = test_app( 'App::GitGot' => [ 'add' , '-f' , $config  , '-D' ]);

  like $result->stdout, qr/
        Add \s repository \s at \s '.*?'\? \s+ \(y\/n\) \s \[y\]: \s y \s+
        Name\? \s+ \[foo.git\]: \s+ foo.git \s+
        Tracking \s remote\? \s+  : \s+

t/04-clone.t  view on Meta::CPAN

use Test::File;
use Test::More;

use App::Cmd::Tester;
use App::GitGot;
use Path::Tiny;
use YAML              qw/ LoadFile /;

my $dir    = Test::BASE::create_tempdir_and_chdir();
my $config = path( "$dir/gitgot" );
file_not_exists_ok $config , 'config does not exist';

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'clone' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: Need the URL to clone/ ,
    'need to give a URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'clone' , '-f' , $config , '-Dq' ,
                                            'http://genehack.org/fake-git-repo.git' ]);

  is $result->stdout    , '' , 'no output';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';

t/05-fork.t  view on Meta::CPAN

  $mock->mock( create_fork => sub {{ ssl_url => 'yeahboi' }} );
}

use App::Cmd::Tester;
use App::GitGot;
use Path::Tiny;
use YAML              qw/ LoadFile /;

my $dir    = Test::BASE::create_tempdir_and_chdir();
my $config = path( "$dir/gitgot" );
file_not_exists_ok $config , 'config does not exist';

$ENV{HOME} = $dir;

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: Need the URL of a repo to fork/ ,
    'need to give a URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ,
                                            'http://not.github.org/' ]);
  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr|ERROR: Can't parse 'http://not.github.org/'| ,
      'need repo URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

Test::BASE::create_github_identity_file();

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config , 'http://not.github.org/' ]);

  is $result->stdout , '' , 'nothing on STDOUT';
  like $result->stderr ,
    qr|ERROR: Can't parse 'http://not.github.org| ,
      'need to give a *github* URL';
  is $result->exit_code , 1 , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config , '--noclone' , '-q' ,
                                            'http://github.com/genehack/fake-git-repo.git' ]);

  is $result->stdout    , '' , 'no output';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';



( run in 0.291 second using v1.01-cache-2.11-cpan-bb97c1e446a )