App-Multigit

 view release on metacpan or  search on metacpan

lib/App/Multigit.pm  view on Meta::CPAN

form is used.

=cut

sub each {
    my $command = shift;
    my $ia_config = shift;
    my $repos = selected_repositories;

    my $f = fmap { _run_in_repo($command, $_[0], $repos->{$_[0]}, $ia_config) }
        foreach => [ keys %$repos ],
        concurrent => $BEHAVIOUR{concurrent_processes},
    ;

    bless $f, 'App::Multigit::Future';
}

=head2 mg_each

This is the exported name of C<each>

    use App::Multigit qw/mg_each/;

=cut

*mg_each = \&each;

sub _run_in_repo {
    my ($cmd, $repo, $config, $ia_config) = @_;

    return App::Multigit::Future->done
        if $BEHAVIOUR{skip_readonly} and $config->{readonly};

    if (ref $cmd eq 'ARRAY') {
        App::Multigit::Repo->new(
            name => $repo,
            config => $config
        )->run($cmd, ia_config => $ia_config);
    }
    else {
        App::Multigit::Repo->new(
            name => $repo,
            config => $config
        )->$cmd;
    }
}

=head2 mkconfig($workdir)

Scans C<$workdir> for git directories and registers each in C<.mgconfig>. If the
config file already exists it will be appended to; existing config will be
preserved where possible.

=cut

sub mkconfig {
    my $workdir = shift // mg_parent;
    my @dirs = File::Find::Rule
        ->relative
        ->directory
        ->not_name('.git')
        ->maxdepth(1)
        ->mindepth(1)
        ->in($workdir);

    my %config;

    # If it's already inited, we'll keep the config
    %config = try {
        %{ all_repositories($workdir) }
    } catch {};

    for my $dir (@dirs) {
        my $url = try {
                _sensible_remote_url($dir);
            }
            catch {
                warn $_;
                0;
            }
        or next;
        $config{$url}->{dir} = $dir;
    }

    write_config(\%config, $workdir);
}

=head2 write_config

Write a .mgconfig configuration file.

=cut

sub write_config
{
    my $config = shift;
    my $workdir = shift // mg_parent;
    my $config_filename = dir($workdir)->file(mgconfig);
    Config::INI::Writer->write_file($config, $config_filename);
}

=head2 clean_config

Checks the C<.mgconfig> for directories that don't exist and removes the associated repo section.

=cut

sub clean_config {
    my $config = all_repositories;
    my $workdir = shift // mg_parent;

    for my $url (keys %$config) {
        my $conf = $config->{$url};
        my $dir = dir($conf->{dir});

        if ($dir->is_relative) {
            $dir = $dir->absolute($workdir);
        }

        unless (-e $dir) {
            delete $config->{$url};



( run in 2.759 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )