From: Vincent Pit Date: Tue, 7 Oct 2008 17:51:04 +0000 (+0200) Subject: Check the value returned by git correctly. POSIX is now a dependency X-Git-Tag: v0.04~13 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Frgit.git;a=commitdiff_plain;h=b70184fed49dd0135e68ab3491475f50521992f3 Check the value returned by git correctly. POSIX is now a dependency --- diff --git a/Makefile.PL b/Makefile.PL index 64d2531..a3b5a0d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -36,6 +36,7 @@ WriteMakefile( 'File::Spec::Functions' => 0, 'List::Util' => 0, 'Object::Tiny' => 0, + 'POSIX' => 0, }, dist => { PREOP => 'pod2text bin/rgit > $(DISTVNAME)/README; ' diff --git a/bin/rgit b/bin/rgit index e6bc910..53312f8 100755 --- a/bin/rgit +++ b/bin/rgit @@ -152,7 +152,7 @@ Add a remote to all repositories in "/foo/bar" to their bare counterpart in C, L, L, L, L and L. +The core modules L, L, L, L, L, L and L. L. diff --git a/lib/App/Rgit/Repository.pm b/lib/App/Rgit/Repository.pm index 82c9f56..43c6d5b 100644 --- a/lib/App/Rgit/Repository.pm +++ b/lib/App/Rgit/Repository.pm @@ -5,6 +5,7 @@ use warnings; use Cwd qw/cwd abs_path/; use File::Spec::Functions qw/catdir splitdir abs2rel file_name_is_absolute/; +use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT/; use Object::Tiny qw/fake repo bare name work/; @@ -129,6 +130,24 @@ sub run { s/\^([\^ngGwWbBR])/$escapes{$1}->()/eg for @args; } system { $conf->git } $conf->git, @args; + if ($? == -1) { + warn "Failed to execute git: $!\n"; + return -1, -1; + } + my $ret; + $ret = WEXITSTATUS($?) if WIFEXITED($?); + my $sig; + if (WIFSIGNALED($?)) { + $sig = WTERMSIG($?); + warn "git died with signal $sig\n"; + if ($sig == SIGINT || $sig == SIGQUIT) { + warn "Aborting.\n"; + exit $sig; + } + } elsif ($ret) { + warn "git returned $ret\n"; + } + return wantarray ? ($ret, $sig) : $ret; } =head2 C diff --git a/t/20-each.t b/t/20-each.t index 1c58246..ca87e8a 100644 --- a/t/20-each.t +++ b/t/20-each.t @@ -102,7 +102,7 @@ for my $cmd (qw/commit FAIL/) { isnt($ar, undef, "each $cmd has a defined object"); my $exit = $ar->run; my $fail = $cmd eq 'FAIL' ? 1 : 0; - is($exit, $fail << 8, "each $cmd returned $fail"); + is($exit, $fail, "each $cmd returned $fail"); my @lines = split /\n/, do { local $/; <$fh> }; my $res = [ map [ split /\|/, $_ ], @lines ]; my $exp = [ map [ $cmd, @$_ ], $fail ? $expected[0] : @expected ];