Skip to content

Commit a785508

Browse files
committed
sane_execvp(): ignore non-directory on $PATH
When you have a non-directory on your PATH, a funny thing happens: $ PATH=$PATH:/bin/sh git foo fatal: cannot exec 'git-foo': Not a directory? Worse yet, as real commands always take precedence over aliases, this behaviour interacts rather badly with them: $ PATH=$PATH:/bin/sh git -c alias.foo=show git foo -s fatal: cannot exec 'git-foo': Not a directory? This is because an ENOTDIR error from the underlying execvp(2) is reported back to the caller of our sane_execvp() wrapper as-is. Translating it to ENOENT, just like the case where we _might_ have the command in an unreadable directory, fixes it. Without an alias, we would get git: 'foo' is not a git command. See 'git --help'. and we use the 'foo' alias when it is available, of course. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 38f865c commit a785508

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

run-command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ int sane_execvp(const char *file, char * const argv[])
7777
*/
7878
if (errno == EACCES && !strchr(file, '/'))
7979
errno = exists_in_PATH(file) ? EACCES : ENOENT;
80+
else if (errno == ENOTDIR && !strchr(file, '/'))
81+
errno = ENOENT;
8082
return -1;
8183
}
8284

0 commit comments

Comments
 (0)