mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
nmbug: Add a git_with_status helper function
Sometimes we want to catch Git errors and handle them, instead of dying with an error message. This lower-level version of git() allows us to get the error status when we want it.
This commit is contained in:
parent
f47eeac0b0
commit
4697e86a52
1 changed files with 10 additions and 3 deletions
|
@ -63,13 +63,20 @@ sub git_pipe {
|
|||
spawn ($envref, defined $ioref ? $ioref : (), defined $dir ? $dir : (), @_);
|
||||
}
|
||||
|
||||
sub git {
|
||||
sub git_with_status {
|
||||
my $fh = git_pipe (@_);
|
||||
my $str = join ('', <$fh>);
|
||||
unless (close $fh) {
|
||||
close $fh;
|
||||
my $status = $?;
|
||||
chomp($str);
|
||||
return ($str, $status);
|
||||
}
|
||||
|
||||
sub git {
|
||||
my ($str, $status) = git_with_status (@_);
|
||||
if ($status) {
|
||||
die "'git @_' exited with nonzero value\n";
|
||||
}
|
||||
chomp($str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue