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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 10, 2023 at 16:51 UTC 6d224ac286d62bb3a10c3697f220b0c10d4b5f51
2 files changed +4 -12
run-command.c
+3 -11
@@ -301,7 +301,6 @@ enum child_errcode {
301 CHILD_ERR_DUP2,
302 CHILD_ERR_CLOSE,
303 CHILD_ERR_SIGPROCMASK,
304 - CHILD_ERR_ENOENT,
304 CHILD_ERR_SILENT,
305 CHILD_ERR_ERRNO
306 };
@@ -384,9 +383,6 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
383 case CHILD_ERR_SIGPROCMASK:
384 error_errno("sigprocmask failed restoring signals");
385 break;
387 - case CHILD_ERR_ENOENT:
388 - error_errno("cannot run %s", cmd->args.v[0]);
389 - break;
386 case CHILD_ERR_SILENT:
387 break;
388 case CHILD_ERR_ERRNO:
@@ -840,13 +836,9 @@ fail_pipe:
836 execve(argv.v[0], (char *const *) argv.v,
837 (char *const *) childenv);
838
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);
842 }
843 atfork_parent(&as);
844 if (cmd->pid < 0)
t/t1800-hook.sh
+1 -1
@@ -164,7 +164,7 @@ test_expect_success 'git hook run a hook with a bad shebang' '
164 # TODO: We should emit the same (or at least a more similar)
165 # error on MINGW (essentially Git for Windows) and all other
166 # 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
168 '
169
170 test_expect_success 'stdin to hooks' '