Skip to content

Commit

Permalink
difftool: exit(0) when usage is printed
Browse files Browse the repository at this point in the history
Prior to this commit, the script exited with an error whenever the
usage string was printed, regardless of the reason it was done. In
cases where usage was printed due to a user request (e.g. '-h'
option), the script should exit without error (exit 0).

This commit adds an argument to the usage function that allows the
exit code to be specified when the function is called.

Signed-off-by: Tim Henigan <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
thenigan authored and gitster committed Mar 23, 2012
1 parent 8508960 commit 2836076
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions git-difftool.perl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

sub usage
{
my $exitcode = shift;
print << 'USAGE';
usage: git difftool [-t|--tool=<tool>]
[-x|--extcmd=<cmd>]
[-g|--gui] [--no-gui]
[--prompt] [-y|--no-prompt]
['git diff' options]
USAGE
exit 1;
exit($exitcode);
}

sub setup_environment
Expand Down Expand Up @@ -58,22 +59,22 @@ sub exe
'x|extcmd:s' => \$extcmd);

if (defined($help)) {
usage();
usage(0);
}
if (defined($difftool_cmd)) {
if (length($difftool_cmd) > 0) {
$ENV{GIT_DIFF_TOOL} = $difftool_cmd;
} else {
print "No <tool> given for --tool=<tool>\n";
usage();
usage(1);
}
}
if (defined($extcmd)) {
if (length($extcmd) > 0) {
$ENV{GIT_DIFFTOOL_EXTCMD} = $extcmd;
} else {
print "No <cmd> given for --extcmd=<cmd>\n";
usage();
usage(1);
}
}
if ($gui) {
Expand Down

0 comments on commit 2836076

Please sign in to comment.