From 8b9150e3e3cc6bf78b21b2e01dcc5e3ed45597a4 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 24 Jun 2006 04:34:44 +0200 Subject: Git.pm: Handle failed commands' output Currently if an external command returns error exit code, a generic exception is thrown and there is no chance for the caller to retrieve the command's output. This patch introduces a Git::Error::Command exception class which is thrown in this case and contains both the error code and the captured command output. You can use the new git_cmd_try statement to fatally catch the exception while producing a user-friendly message. It also adds command_close_pipe() for easier checking of exit status of a command we have just a pipe handle of. It has partial forward dependency on the next patch, but basically only in the area of documentation. Signed-off-by: Petr Baudis Signed-off-by: Junio C Hamano --- git-fmt-merge-msg.perl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'git-fmt-merge-msg.perl') diff --git a/git-fmt-merge-msg.perl b/git-fmt-merge-msg.perl index be2a48cf6..f86231e14 100755 --- a/git-fmt-merge-msg.perl +++ b/git-fmt-merge-msg.perl @@ -7,6 +7,7 @@ use strict; use Git; +use Error qw(:try); my $repo = Git->repository(); @@ -31,7 +32,17 @@ sub andjoin { } sub repoconfig { - my ($val) = $repo->command_oneline('repo-config', '--get', 'merge.summary'); + my $val; + try { + $val = $repo->command_oneline('repo-config', '--get', 'merge.summary'); + } catch Git::Error::Command with { + my ($E) = shift; + if ($E->value() == 1) { + return undef; + } else { + throw $E; + } + }; return $val; } -- cgit v1.2.1