CPAN-InGit

 view release on metacpan or  search on metacpan

t/16-remote-branches.t  view on Meta::CPAN

   return CPAN::InGit->new(repo => $git);
};

subtest lookup => sub {
   my $repo= $clone->('clone.git', 'origin');
   is( [ map $_->shorthand, $repo->git_repo->branches('local') ], [], 'no local branches' );
   is( [ $repo->branch_names ], [ 'source', 'team/app' ], 'branch_names' );
   is( $repo->lookup_branch('team/app'), object { call shorthand => 'origin/team/app'; call is_remote => T; }, 'lookup_branch' );
   is( $repo->local_branch_name($repo->lookup_branch('team/app')), 'team/app', 'local_branch_name' );
   is( $repo->lookup_branch('nope'), undef, 'no such branch' );
   is( $repo->lookup_tree('nope'), undef, 'lookup_tree of no such branch' );
   ok( $repo->lookup_tree('source'), 'lookup_tree' );

   my $app= $repo->get_archive_tree('team/app');
   is( $app, object { call name => 'team/app'; call default_import_sources => ['source']; }, 'get_archive_tree' );
   is( $app->get_module_version('Example'), '1.00', 'reads the index of the remote branch' );
   is( $app->find_upgrades,
      [ hash { field author_path => 'A/AU/AUTHOR/Example-1.00.tar.gz'; field upgrades => [ hash { field source => 'source'; etc } ]; etc } ],
      'import sources resolve through the remote too' );
   is( [ map $_->shorthand, $repo->git_repo->branches('local') ], [], 'reading created nothing' );
};

subtest commit => sub {
   my $repo= $clone->('clone2.git', 'origin');
   my $remote_commit= $repo->lookup_branch('team/app')->peel('commit')->id;
   my $app= $repo->get_archive_tree('team/app');
   $app->index_distribution('A/AU/AUTHOR/Example-1.02.tar.gz', { Example => '1.02' });
   my $commit= $app->commit('Upgrade');
   is( [ map $_->shorthand, $repo->git_repo->branches('local') ], ['team/app'], 'commit created the local branch' );
   my $local= $repo->lookup_branch('team/app');
   is( $local, object {
         call is_remote => F;
         call upstream_name => 'refs/remotes/origin/team/app';
         call remote_name => 'origin';
      }, 'which tracks the remote branch' );
   is( $local->peel('commit')->id, $commit->id, 'at the new commit' );
   is( [ map $_->id, $commit->parents ], [ $remote_commit ], 'on top of the remote commit' );
   is( Git::Raw::Branch->lookup($repo->git_repo, 'origin/team/app', 0)->peel('commit')->id, $remote_commit,
      'remote-tracking branch was not moved' );
   is( $app->branch->is_remote, F, 'tree now refers to the local branch' );
   $app->index_distribution('B/BB/BOB/Other-1.tar.gz', { Other => '1' });
   $app->commit('Again');
   is( $repo->get_archive_tree('team/app')->get_module_version('Other'), '1', 'local branch is preferred afterward' );
};

subtest server => sub {
   require Test::Mojo;
   require CPAN::InGit::Server;
   my $repo= $clone->('clone4.git', 'origin');
   my $t= Test::Mojo->new('Mojolicious');
   CPAN::InGit::Server->mount($t->app->routes->any('/pan'), $repo, app => $t->app, index_branches => 1);
   $t->get_ok('/pan/')->status_is(200)->content_like(qr{~branch/team~app/}, 'repo index lists a remote-only branch');
   $t->get_ok('/pan/~branch/team~app/')->status_is(200)->content_like(qr/Example/);
   $t->get_ok('/pan/~branch/team~app/modules/02packages.details.txt')->status_is(200)
      ->content_like(qr/^Example\s+1\.00\s/m);
   $t->get_ok('/pan/~branch/nope/')->status_is(404);
   is( [ map $_->shorthand, $repo->git_repo->branches('local') ], [], 'serving created nothing' );
};

subtest ambiguous => sub {
   my $repo= $clone->('clone3.git', 'origin', 'backup');
   like( dies { $repo->lookup_branch('source') }, qr/more than one remote \(backup, origin\)/, 'two remotes' );
   $repo->git_repo->config->str('checkout.defaultRemote', 'backup');
   is( $repo->lookup_branch('source')->shorthand, 'backup/source', 'checkout.defaultRemote' );
   is( [ $repo->branch_names ], [ 'source', 'team/app' ], 'branch_names has each once' );
};

done_testing;



( run in 0.643 second using v1.01-cache-2.11-cpan-f5f21f1076c )