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@xxxxxxxx> --- git.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index 3805616..917bc9e 100644 --- a/git.c +++ b/git.c @@ -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 | RUN_CLEAN_ON_EXIT); - 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; -- 1.7.9.5.5.g9b709b -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html