]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: report exec error even on ENOENT
authorRené Scharfe <l.s.r@web.de>
Sat, 10 Jun 2023 14:51:21 +0000 (16:51 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jun 2023 18:00:22 +0000 (11:00 -0700)
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>
run-command.c
t/t1800-hook.sh

index 6bd16acb0603b16a71c729978bba812326ca9400..ea192882fb020f8d250dc295196463f4feedf9ec 100644 (file)
@@ -301,7 +301,6 @@ enum child_errcode {
        CHILD_ERR_DUP2,
        CHILD_ERR_CLOSE,
        CHILD_ERR_SIGPROCMASK,
-       CHILD_ERR_ENOENT,
        CHILD_ERR_SILENT,
        CHILD_ERR_ERRNO
 };
@@ -384,9 +383,6 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
        case CHILD_ERR_SIGPROCMASK:
                error_errno("sigprocmask failed restoring signals");
                break;
-       case CHILD_ERR_ENOENT:
-               error_errno("cannot run %s", cmd->args.v[0]);
-               break;
        case CHILD_ERR_SILENT:
                break;
        case CHILD_ERR_ERRNO:
@@ -840,13 +836,9 @@ fail_pipe:
                        execve(argv.v[0], (char *const *) argv.v,
                               (char *const *) childenv);
 
-               if (errno == ENOENT) {
-                       if (cmd->silent_exec_failure)
-                               child_die(CHILD_ERR_SILENT);
-                       child_die(CHILD_ERR_ENOENT);
-               } else {
-                       child_die(CHILD_ERR_ERRNO);
-               }
+               if (cmd->silent_exec_failure && errno == ENOENT)
+                       child_die(CHILD_ERR_SILENT);
+               child_die(CHILD_ERR_ERRNO);
        }
        atfork_parent(&as);
        if (cmd->pid < 0)
index c156d6decc3b761099b2e8365a5774cc0b600ac0..8b0234cf2d5d96980403d65b844639715acfe91b 100755 (executable)
@@ -164,7 +164,7 @@ test_expect_success 'git hook run a hook with a bad shebang' '
        # TODO: We should emit the same (or at least a more similar)
        # error on MINGW (essentially Git for Windows) and all other
        # platforms.. See the OS-specific code in start_command()
-       grep -E "^(error|fatal): cannot (exec|run|spawn) .*bad-hooks/test-hook" err
+       grep -E "^(error|fatal): cannot (exec|spawn) .*bad-hooks/test-hook" err
 '
 
 test_expect_success 'stdin to hooks' '