App-RepoSync

 view release on metacpan or  search on metacpan

lib/App/RepoSync/Command/Import.pm  view on Meta::CPAN

package App::RepoSync::Command::Import;
use 5.10.0;
use warnings;
use strict;
use base qw( CLI::Framework::Command );
use File::Path qw(mkpath);
use Try::Tiny;
use Cwd;
use YAML;
use App::RepoSync::Export;
use App::RepoSync::SystemUtil qw(system_or_die chdir_qx);
use Term::ANSIColor;

sub option_spec {
    [ 'help|h'      => 'show help' ],
    [ 'verbose|v'   => 'be verbose' ],
    # [ 'db=s'        => 'path to SQLite database file' ],
}

sub info {
    print color('green'), @_ , color('reset') , "\n";
}

sub warning {
    print color('red'), @_ , color('reset') , "\n";
}

sub run {
    my ($self,$opts,@args) = @_;
    my ($import_file) = @args;

    my $back_dir = getcwd();

    my $verbose      = $opts->{verbose};
    my $svn_opts     = $verbose ? qq() : qq(-q);
    my $git_opts     = $verbose ? qq(--verbose) : qq(--quiet);
    my $git_svn_opts = $verbose ? qq() : qq(--quiet);
    my $hg_opts      = $verbose ? qq() : qq(--quiet);

    my $data = YAML::LoadFile $import_file;

    info "importing @{[ scalar @{ $data->{repos} } ]} repositories.";

    for my $repo ( @{ $data->{repos} } ) {
        given ($repo->{type} ) {
            when('svn') { 
                my $path = $repo->{path};
                my $url = $repo->{url};
                if ( -e $path ) {
                    info "svn: updating $path from $url";

                    system_or_die("svn update $svn_opts --trust-server-cert --non-interactive $path",
                            "svn update");
                }
                else {
                    info "svn: checking out $url into $path";
                    system_or_die("svn checkout $svn_opts --trust-server-cert --non-interactive $url $path",
                            "svn checkout");
                }
            }
            when('git') { 
                my $path = $repo->{path};
                my $url = $repo->{url};
                my %remotes = %{ $repo->{remotes} };
                if( -e $path ) {
                    info "git: updating $path";
                    info "git: remote update and prune";



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