App-Multigit

 view release on metacpan or  search on metacpan

script/mg-init  view on Meta::CPAN

#!perl
use strict;
use warnings;
use 5.014;

use Getopt::Long qw(:config gnu_getopt);
use App::Multigit qw(mgconfig mg_parent all_repositories mg_each);
use App::Multigit::Script ();  # Avoid trying to get --workdir and chdir to it.
use Future;
use curry;

use Cwd qw(getcwd);
use File::Copy;
use HTTP::Tiny;
use Path::Class;
use Try::Tiny;

my %options = App::Multigit::Script::get_default_options;
GetOptions(\%options,
    'update-only|u',
    'clean|c',
    'remove-repos|rm',
);

die "update-only is not compatible with clean"
    if $options{'update-only'} and $options{clean};
die "update-only is not compatible with remove-missing"
    if $options{'update-only'} and $options{'remove-missing'};

$options{workdir} //= getcwd;

chdir $options{workdir};

$options{workdir} = dir($options{workdir});

my $config = shift;

if ($config) {
    if($config eq '-') {
        # read updated config from stdout
        copy(\*STDIN, mgconfig);
    }
    elsif ($config =~ m{://}) {
        HTTP::Tiny->new->mirror($config, mgconfig);
    }
    else {
        copy($config, mgconfig);
    }
}

my $existing_mg = try {
    mg_parent
}
catch {
    die "Failed to initialise from $config.\n" if $config;
    return;
};

if ($existing_mg) {
    my $f = mg_each(sub {
        my $repo = shift;
        return Future->done if -e $repo->config->{dir};

        return Future->done
            if $options{'update-only'}
            or $options{clean};

        my $cmd = [
            qw(git clone),
            (
                $repo->config->{branch} 
                ? ('-b', $repo->config->{branch} )
                : ()
            ),
            $repo->config->{url}
        ];



( run in 0.787 second using v1.01-cache-2.11-cpan-39bf76dae61 )