Skip to content

Commit 6d224ac

Browse files
rscharfegitster
authored andcommitted
run-command: report exec error even on ENOENT
If execve(2) fails with ENOENT and we report the error, we use the format "cannot run %s", followed by the actual error message. For other errors we use "cannot exec '%s'". Stop making this subtle distinction and use the second format for all execve(2) errors. This simplifies the code and makes the prefix more precise by indicating the failed operation. It also allows us to slightly simplify t1800.16. On Windows -- which lacks execve(2) -- we already use a single format in all cases: "cannot spawn %s". Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b6fe8b commit 6d224ac

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

run-command.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ enum child_errcode {
301301
CHILD_ERR_DUP2,
302302
CHILD_ERR_CLOSE,
303303
CHILD_ERR_SIGPROCMASK,
304-
CHILD_ERR_ENOENT,
305304
CHILD_ERR_SILENT,
306305
CHILD_ERR_ERRNO
307306
};
@@ -384,9 +383,6 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
384383
case CHILD_ERR_SIGPROCMASK:
385384
error_errno("sigprocmask failed restoring signals");
386385
break;
387-
case CHILD_ERR_ENOENT:
388-
error_errno("cannot run %s", cmd->args.v[0]);
389-
break;
390386
case CHILD_ERR_SILENT:
391387
break;
392388
case CHILD_ERR_ERRNO:
@@ -840,13 +836,9 @@ int start_command(struct child_process *cmd)
840836
execve(argv.v[0], (char *const *) argv.v,
841837
(char *const *) childenv);
842838

843-
if (errno == ENOENT) {
844-
if (cmd->silent_exec_failure)
845-
child_die(CHILD_ERR_SILENT);
846-
child_die(CHILD_ERR_ENOENT);
847-
} else {
848-
child_die(CHILD_ERR_ERRNO);
849-
}
839+
if (cmd->silent_exec_failure && errno == ENOENT)
840+
child_die(CHILD_ERR_SILENT);
841+
child_die(CHILD_ERR_ERRNO);
850842
}
851843
atfork_parent(&as);
852844
if (cmd->pid < 0)

t/t1800-hook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ test_expect_success 'git hook run a hook with a bad shebang' '
164164
# TODO: We should emit the same (or at least a more similar)
165165
# error on MINGW (essentially Git for Windows) and all other
166166
# platforms.. See the OS-specific code in start_command()
167-
grep -E "^(error|fatal): cannot (exec|run|spawn) .*bad-hooks/test-hook" err
167+
grep -E "^(error|fatal): cannot (exec|spawn) .*bad-hooks/test-hook" err
168168
'
169169

170170
test_expect_success 'stdin to hooks' '

0 commit comments

Comments
 (0)