From: Vincent Pit Date: Mon, 6 Oct 2008 16:30:32 +0000 (+0200) Subject: Sort the list of repositories by repository path. Test for git returning non-zero X-Git-Tag: v0.03~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Frgit.git;a=commitdiff_plain;h=ab6f258a18f074ed6f18d29d98ea13b6d708e3a2 Sort the list of repositories by repository path. Test for git returning non-zero --- diff --git a/bin/rgit b/bin/rgit index 559fd9f..101d634 100755 --- a/bin/rgit +++ b/bin/rgit @@ -53,7 +53,7 @@ Version 0.02 =head1 DESCRIPTION -This utility recursively searches in the current directory (or in the directory given by the C environment variable if it's set) for all git repositories, C into each of them, and executes the specified git command. +This utility recursively searches in the current directory (or in the directory given by the C environment variable if it's set) for all git repositories, sort this list by the repository path, C into each of them, and executes the specified git command. Moreover, those formats are substuted in the arguments before running the command : =over 4 diff --git a/lib/App/Rgit/Config/Default.pm b/lib/App/Rgit/Config/Default.pm index 98b085f..9203d81 100644 --- a/lib/App/Rgit/Config/Default.pm +++ b/lib/App/Rgit/Config/Default.pm @@ -51,7 +51,7 @@ sub repos { }, follow => 1 }, $self->root; - $self->{repos} = [ values %repos ]; + $self->{repos} = [ sort { $a->repo cmp $b->repo } values %repos ]; } =head1 SEE ALSO diff --git a/t/20-each.t b/t/20-each.t index 1e14fac..4180a93 100644 --- a/t/20-each.t +++ b/t/20-each.t @@ -7,7 +7,7 @@ use Cwd qw/cwd abs_path/; use File::Spec::Functions qw/catdir catfile/; use File::Temp qw/tempfile tempdir/; -use Test::More tests => 2 + 3 * 1; +use Test::More tests => 2 + 3 * 2; use App::Rgit; @@ -50,7 +50,7 @@ sub repo { my $tmpdir = tempdir(CLEANUP => 1); my $cwd = cwd; chdir $tmpdir or die "chdir($tmpdir): $!"; -my @expected = sort { $a->[0] cmp $b->[0] } build({ +my @expected = sort { $a->[1] cmp $b->[1] } build({ x => { a => { _ => repo('a', 0), @@ -91,7 +91,7 @@ is(grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references'); '^n' ], @expected; -for my $cmd (qw/commit/) { +for my $cmd (qw/commit FAIL/) { my ($fh, $filename) = tempfile(UNLINK => 1); my $ar = App::Rgit->new( git => abs_path('t/bin/git'), @@ -101,9 +101,10 @@ for my $cmd (qw/commit/) { ); isnt($ar, undef, "each $cmd has a defined object"); my $exit = $ar->run; - is($exit, 0, "each $cmd returned 0"); - my @lines = sort split /\n/, do { local $/; <$fh> }; + my $fail = $cmd eq 'FAIL' ? 1 : 0; + is($exit, $fail << 8, "each $cmd returned $fail"); + my @lines = split /\n/, do { local $/; <$fh> }; my $res = [ map [ split /\|/, $_ ], @lines ]; - my $exp = [ map [ $cmd, @$_ ], @expected ]; + my $exp = [ map [ $cmd, @$_ ], $fail ? $expected[0] : @expected ]; is_deeply($res, $exp, "each $cmd did the right thing"); } diff --git a/t/bin/git b/t/bin/git index 6d769f6..d93614d 100755 --- a/t/bin/git +++ b/t/bin/git @@ -3,7 +3,10 @@ # This has to work with olde perls my $filename = shift @ARGV; +my $cmd = shift @ARGV; open FH, ">>$filename" or die "open($filename): $!"; -print FH join '|', @ARGV; +print FH join '|', $cmd, @ARGV; print FH "\n"; close FH; + +exit(($cmd && $cmd eq 'FAIL') ? 1 : 0);