App-GitGot
view release on metacpan or search on metacpan
lib/App/GitGot/Command/checkout.pm view on Meta::CPAN
package App::GitGot::Command::checkout;
our $AUTHORITY = 'cpan:GENEHACK';
$App::GitGot::Command::checkout::VERSION = '1.339';
# ABSTRACT: checkout specific branch for managed repositories
use 5.014;
use Try::Tiny;
use App::GitGot -command;
use Moo;
extends 'App::GitGot::Command';
use namespace::autoclean;
sub options {
my( $class , $app ) = @_;
return (
[ 'branch=s' => 'branch to checkout in the different repos' => { required => 1 } ] ,
[ 'create|b' => 'create branch like checkout -b in each of the repos' ],
);
}
sub _execute {
my( $self, $opt, $args ) = @_;
$self->_checkout( $self->opt->branch, $self->active_repos );
}
sub _checkout {
my( $self , $branch, @repos ) = @_;
my $max_len = $self->max_length_of_an_active_repo_label;
REPO: for my $repo ( @repos ) {
next REPO unless $repo->repo;
my $name = $repo->name;
my $msg = sprintf "%3d) %-${max_len}s : ", $repo->number, $repo->label;
my ( $status, $fxn );
my $repo_type = $repo->type;
if ( $repo_type eq 'git' ) { $fxn = '_git_checkout' }
### FIXME elsif( $repo_type eq 'svn' ) { $fxn = 'svn_update' }
else { $status = $self->error("ERROR: repo type '$_' not supported") }
$status = $self->$fxn($repo, $branch) if ($fxn);
next REPO if $self->quiet and !$status;
say "$msg$status";
}
}
sub _git_checkout {
my ( $self, $entry, $branch ) = @_
or die "Need entry";
# no callback because we need to run checkout even if just cloned
$self->_git_clone_or_callback( $entry , sub { '' } );
my $msg = '';
my @o = try { $entry->checkout($self->opt->create ? '-b' : (), $branch); } catch { $_->error };
my @err = try { @{ $entry->_wrapper->ERR } } catch { $_ };
# Typically STDOUT will contain something similar to
# Your branch is up-to-date with 'origin/main'.
# or
# Your branch is ahead of 'origin/main' by 2 commits.
( run in 1.011 second using v1.01-cache-2.11-cpan-0d23b851a93 )