diff options
author | Jeff King <peff@peff.net> | 2012-03-27 14:05:03 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-03-27 12:12:26 -0700 |
commit | e2363a785f6cc6aec624292a6aa01d26e93cffb2 (patch) | |
tree | 0610ae0c48271dd43eba91c5f383071a1b0ea856 | |
parent | f2b8e7343fc1951653800dc65aad2cfe6e763078 (diff) | |
download | git-e2363a785f6cc6aec624292a6aa01d26e93cffb2.tar.gz |
git: continue alias lookup on EACCES errors
If git receives an EACCES error while trying to execute an
external command, we currently give up and report the error.
However, the EACCES may be caused by an inaccessible
directory in the user's PATH.
In this case, execvp will skip over the inaccessible
directory and keep searching the PATH. If it finds
something, then that gets executed. Otherwise, the earlier
EACCES is remembered and returned.
However, git does not implement the same rule when looking
up aliases. It will return immediately upon seeing EACCES
from execvp, without trying aliases. This renders aliases
unusable if there is an inaccessible directory in the PATH.
This patch implements a logical extension of execvp's lookup
rules to aliases. We will try to find aliases even after
execvp returns EACCES. If there is an alias, then we expand
it as usual. If ther eisn't, then we will remember and
report the EACCES error.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | git.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -496,7 +496,7 @@ static void execv_dashed_external(const char **argv) * OK to return. Otherwise, we just pass along the status code. */ status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE); - if (status >= 0 || errno != ENOENT) + if (status >= 0 || (errno != ENOENT && errno != EACCES)) exit(status); argv[0] = tmp; @@ -586,14 +586,16 @@ int main(int argc, const char **argv) static int done_help = 0; static int was_alias = 0; was_alias = run_argv(&argc, &argv); - if (errno != ENOENT) - break; - if (was_alias) { + if (was_alias && (errno == ENOENT || errno == EACCES)) { fprintf(stderr, "Expansion of alias '%s' failed; " - "'%s' is not a git command\n", - cmd, argv[0]); + "'%s'%s\n", cmd, argv[0], + errno == ENOENT ? + " is not a git command" : + ": Permission denied"); exit(1); } + if (errno != ENOENT) + break; if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; |