App-Multigit
view release on metacpan or search on metacpan
Future that each returns will be a useless list of all flattened
hashes. For this reason it is not actually very much use to do this -
but it is not completely useless, because all hashes are the same size:
my $future = App::Multigit::each([qw/git reset --hard HEAD/]);
my @result = $future->get;
my $natatime = List::MoreUtils::natatime(10, @result);
while (my %data = $natatime->()) {
say $data{stdout};
}
However, the %data hashes do not contain repository information; just
the output. It is expected that if repository information is required,
the closure form is used.
mg_each
This is the exported name of each
examples/mg-branch view on Meta::CPAN
$repo->run([ qw(git branch), @ARGV ])
# ... then report on the outputs.
->finally($repo->curry::report)
});
# finally will gather up all output, whether or not the command succeeded.
# Repo::report will then format it for output as a (directory => output) hash.
my %report = $future->get;
for my $repo (sort keys %report) {
say for $repo, $report{$repo};
}
# POD is used to document the script
=head1 SYNOPSIS
mg-branch ARGV
Runs `git branch argv` on each repository. See `git help branch`.
examples/mg-closes view on Meta::CPAN
# This hash is influenced by the Futures returned later, in show_results.
# The Futures that complete with nothing contribute nothing to this hash.
# We are careful to make sure our Futures complete with even-sized lists,
# because we're cognisant of the fact they'll end up here.
my %done = $future->get;
for my $dir (keys %done) {
chomp $done{$dir};
if ($done{$dir}) {
say for "$dir:", $done{$dir};
}
else {
say $dir;
}
}
# show_results returns a closure. The closure accepts a C<%data> hash,
# documented in L<App::Multigit::Repo|App::Multigit::Repo/run>. The subref is
# run by Future for each individual repository, when the first command
# completes.
sub show_results {
my $repo = shift;
return sub {
lib/App/Multigit.pm view on Meta::CPAN
useless list of all flattened hashes. For this reason it is not actually very
much use to do this - but it is not completely useless, because all hashes are
the same size:
my $future = App::Multigit::each([qw/git reset --hard HEAD/]);
my @result = $future->get;
my $natatime = List::MoreUtils::natatime(10, @result);
while (my %data = $natatime->()) {
say $data{stdout};
}
However, the C<%data> hashes do not contain repository information; just the
output. It is expected that if repository information is required, the closure
form is used.
=cut
sub each {
my $command = shift;
script/mg-each view on Meta::CPAN
my %result = mg_each(
sub {
my $repo = shift;
$repo->run(\@ARGV)
->finally($repo->curry::report)
})
->get;
for (sort keys %result) {
say $_ unless $App::Multigit::BEHAVIOUR{output_only};
say $result{$_};
}
=head1 SYNOPSIS
mg each [command]
Runs `command` in each repository and reports the results.
Use options to C<mg> itself to control the output.
script/mg-env view on Meta::CPAN
'reset!',
'reset-only!',
);
push @{$options{'path-dir'} }, qw(bin script);
$ENV{MG_ENV_ORIGINAL_PERL5LIB} //= $ENV{PERL5LIB} || '';
$ENV{MG_ENV_ORIGINAL_PATH} //= $ENV{PATH} || '';
if ($options{reset}) {
say "PATH=$ENV{MG_ENV_ORIGINAL_PATH}; export PATH;";
say "PERL5LIB=$ENV{MG_ENV_ORIGINAL_PERL5LIB}; export PERL5LIB;";
say "unset MG_ENV_ORIGINAL_PATH; unset MG_ENV_ORIGINAL_PERL5LIB;";
exit if $options{'reset-only'};
}
my $future = mg_each(\&add_environment);
say "$_=$ENV{$_}; export $_;"
for qw/ MG_ENV_ORIGINAL_PATH MG_ENV_ORIGINAL_PERL5LIB/;
say for $future->get;
sub add_environment {
my ($repo) = @_;
my $dir = $repo->config->{dir};
if ($options{absolute}) {
$dir = dir($dir)->absolute;
}
my @env;
script/mg-grep view on Meta::CPAN
'exitcode|e!',
'invert|v!',
);
my $future = mg_each(sub {
my $repo = shift;
$repo->run(\@ARGV)
->finally($options{debug} ? $repo->curry::report : filter($repo))
});
say for $future->get;
sub filter {
my $repo = shift;
sub {
my %data = @_;
my $test = $TESTS{$options{exitcode} ? 'exitcode' : 'stdout'};
my $pass = $test->(%data);
$pass = !$pass if $options{invert};
script/mg-init view on Meta::CPAN
? ('-b', $repo->config->{branch} )
: ()
),
$repo->config->{url}
];
$repo->run($cmd, ia_config => { no_cd => 1 })
->finally($repo->curry::report)
});
say for $f->get;
}
# Create the config if we don't have one.
# Don't update it if we're going to delete dirs.
if (not $existing_mg
or not $options{'remove-missing'})
{
App::Multigit::mkconfig($options{workdir});
}
if ($options{'remove-missing'}) {
my %dirs = map { $_->{dir} => 1 } values %{ all_repositories($options{workdir}) };
for my $dir ($options{workdir}->children) {
next unless $dir->is_dir;
next if $dirs{ $dir->relative($options{workdir}) };
$dir->rmtree and say "Removed " . $dir->relative($options{workdir});
}
}
App::Multigit::clean_config($options{workdir})
if $options{clean};
=head1 SYNOPSIS
mg init [--update-only|u] [--clean|c] [--remove-missing|--rm|-R] [FILE]
script/mg-root view on Meta::CPAN
#!perl
use strict;
use warnings;
use 5.014;
use App::Multigit;
use App::Multigit::Script;
say App::Multigit::mg_parent();
=head1 SYNOPSIS
mg root
Reports the closest parent directory with a .mgconfig file in it.
script/mg-st view on Meta::CPAN
$repo->run(
[qw/ git status /, @ARGV]
)
->then(\&prune)
->finally($repo->curry::report)
});
my %report = $future->get;
for my $repo (sort keys %report) {
say for $repo, $report{$repo};
}
sub prune {
my %data = @_;
if ($data{stdout} =~ /nothing to commit/i
and $data{stdout} =~ /Your branch is up-to-date/i
and not $options{debug}) {
Future->done
}
( run in 1.526 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )