Skip to content

Commit dcedba1

Browse files
committed
Merge branch 'rs/run-command-exec-error-on-noent'
Simplify error message when run-command fails to start a command. * rs/run-command-exec-error-on-noent: run-command: report exec error even on ENOENT t1800: loosen matching of error message for bad shebang
2 parents 5ee8fcd + 6d224ac commit dcedba1

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

run-command.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ enum child_errcode {
307307
CHILD_ERR_DUP2,
308308
CHILD_ERR_CLOSE,
309309
CHILD_ERR_SIGPROCMASK,
310-
CHILD_ERR_ENOENT,
311310
CHILD_ERR_SILENT,
312311
CHILD_ERR_ERRNO
313312
};
@@ -390,9 +389,6 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
390389
case CHILD_ERR_SIGPROCMASK:
391390
error_errno("sigprocmask failed restoring signals");
392391
break;
393-
case CHILD_ERR_ENOENT:
394-
error_errno("cannot run %s", cmd->args.v[0]);
395-
break;
396392
case CHILD_ERR_SILENT:
397393
break;
398394
case CHILD_ERR_ERRNO:
@@ -846,13 +842,9 @@ int start_command(struct child_process *cmd)
846842
execve(argv.v[0], (char *const *) argv.v,
847843
(char *const *) childenv);
848844

849-
if (errno == ENOENT) {
850-
if (cmd->silent_exec_failure)
851-
child_die(CHILD_ERR_SILENT);
852-
child_die(CHILD_ERR_ENOENT);
853-
} else {
854-
child_die(CHILD_ERR_ERRNO);
855-
}
845+
if (cmd->silent_exec_failure && errno == ENOENT)
846+
child_die(CHILD_ERR_SILENT);
847+
child_die(CHILD_ERR_ERRNO);
856848
}
857849
atfork_parent(&as);
858850
if (cmd->pid < 0)

t/t1800-hook.sh

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,15 @@ test_expect_success 'git hook run a hook with a bad shebang' '
156156
mkdir bad-hooks &&
157157
write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
158158
159-
# TODO: We should emit the same (or at least a more similar)
160-
# error on MINGW (essentially Git for Windows) and all other
161-
# platforms.. See the OS-specific code in start_command()
162-
if test_have_prereq !MINGW
163-
then
164-
cat >expect <<-\EOF
165-
fatal: cannot run bad-hooks/test-hook: ...
166-
EOF
167-
else
168-
cat >expect <<-\EOF
169-
error: cannot spawn bad-hooks/test-hook: ...
170-
EOF
171-
fi &&
172159
test_expect_code 1 git \
173160
-c core.hooksPath=bad-hooks \
174161
hook run test-hook >out 2>err &&
175162
test_must_be_empty out &&
176-
sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
177-
test_cmp expect actual
163+
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|spawn) .*bad-hooks/test-hook" err
178168
'
179169

180170
test_expect_success 'stdin to hooks' '

0 commit comments

Comments
 (0)