Skip to contentSkip to conversation

Git 2.28.0-rc1 t1800 message text comparison

BUG In review [email protected] 3 participants 13 messages Sep 22, 2022 – Jun 12, 2023

lore
Share & tools
lore
#0 lore raw

Rc1 is looking good except for this test.

We get a diff as follows:

-fatal: cannot run bad-hooks/test-hook: ... +fatal: cannot exec 'bad-hooks/test-hook': Permission denied

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

Regards,
Randall

#1 lore raw

RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Quoted 7 lines · On September 22, 2022 3:02 PM, I wrote:

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

The subject should have been 2.38.0, not 2.28.0.

#2 lore raw

RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison

In reply to [email protected]
Quoted 8 lines · On September 22, 2022 3:03 PM, I wrote:
Quoted 7 lines · On September 22, 2022 3:02 PM, I wrote:

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

A patch that might work is as follows:

t/t1800-hook.sh +0 -0
index 43fcb7c0bf..9a723631a2 100755
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad

shebang' '

                -c core.hooksPath=bad-hooks \
                hook run test-hook >out 2>err &&
        test_must_be_empty out &&
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \

+ sed -e "s/$quot//g" | \
+ sed -e "s/test-hook: .*/test-hook: .../" >actual &&
test_cmp expect actual
'

This does not require setting up a prerequisite for NonStop and the technique might make the MING code easier but adding a change from spawn to run.

-Randall

#3 lore raw

RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Quoted 37 lines · On September 23, 2022 4:43 PM, I wrote:
Quoted 8 lines · On September 22, 2022 3:03 PM, I wrote:
Quoted 7 lines · On September 22, 2022 3:02 PM, I wrote:

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

A patch that might work is as follows:

t/t1800-hook.sh index 43fcb7c0bf..9a723631a2 renamed from t/t1800-hook.sh +0 -0

100755

t/t1800-hook.sh +0 -0
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad

shebang' '

               -c core.hooksPath=bad-hooks \
               hook run test-hook >out 2>err &&
       test_must_be_empty out &&
t/t1800-hook.sh +4 -1
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \
+               sed -e "s/$quot//g" | \
+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
       test_cmp expect actual

'

Quoted 1 line

This does not require setting up a prerequisite for NonStop and the

technique

Quoted 1 line

might make the MING code easier but adding a change from spawn to run.

This is still broken on NonStop. Is there any hope of a resolution?

Thanks,
Randall

#4 lore raw

Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Am 14.12.22 um 06:53 schrieb [email protected]:

Quoted 38 lines · On September 23, 2022 4:43 PM, I wrote:
Quoted 37 lines · On September 22, 2022 3:03 PM, I wrote:
Quoted 8 lines · On September 22, 2022 3:02 PM, I wrote:
Quoted 7 lines

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

A patch that might work is as follows:

t/t1800-hook.sh index 43fcb7c0bf..9a723631a2 renamed from t/t1800-hook.sh +0 -0

100755

t/t1800-hook.sh +0 -0
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad

shebang' '

               -c core.hooksPath=bad-hooks \
               hook run test-hook >out 2>err &&
       test_must_be_empty out &&
t/t1800-hook.sh +4 -1
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \
+               sed -e "s/$quot//g" | \
+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
       test_cmp expect actual

'

Quoted 5 lines
Quoted 1 line

This does not require setting up a prerequisite for NonStop and the

technique

Quoted 1 line

might make the MING code easier but adding a change from spawn to run.

This is still broken on NonStop. Is there any hope of a resolution?

So trying to execute an executable file consisting only of the line "#!/bad/path/no/spaces" causes NonStop to report "Permission denied"? That message text belongs to error code EACCES, not to EPERM ("Operation not permitted"), right?

POSIX allows execve to return EACCES if the file to execute is not a regular file and executing that file type is not supported or if permissions are missing to one of its path components.

Either you have something called /bad that is not a regular file (e.g. a directory) -- then it's just a matter of changing the test to use a different supposedly non-existing filename, perhaps by creating and deleting a temporary file for just that purpose.

Or NonStop correctly returns ENOEXEC on the first execve(2) call in run-command.c and returns ENOACCES on the fallback with SHELL_PATH (default value /usr/coreutils/bin/bash), because you are not allowed to execute that shell. Then SHELL_PATH needs to be corrected.

Or valid shells need to be placed in some kind of allow list to be accepted in #!-lines, lest NonStop returns ENOACCES on them. Or NonStop is simply reporting a bogus error code for some reason. In those cases you probably need an execve) compat/ wrapper that corrects the error code.

Or I'm missing something here, which is a relatively safe bet. Anyway, depending on the cause of the "Permission denied" message, loosening the textual comparison in the test might not be enough. There may not be a point for end users to distinguish between "exec" vs. "run", but the silent_exec_failure feature of run-command depends on the error code being ENOENT.

René

#5 lore raw

RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Quoted 42 lines · René Scharfe

Am 14.12.22 um 06:53 schrieb [email protected]:

Quoted 41 lines · On September 23, 2022 4:43 PM, I wrote:
Quoted 38 lines · On September 22, 2022 3:03 PM, I wrote:
Quoted 8 lines · On September 22, 2022 3:02 PM, I wrote:
Quoted 7 lines

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

A patch that might work is as follows:

t/t1800-hook.sh index renamed from t/t1800-hook.sh +0 -0

43fcb7c0bf..9a723631a2
100755

t/t1800-hook.sh +0 -0
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a

bad shebang' '

               -c core.hooksPath=bad-hooks \
               hook run test-hook >out 2>err &&
       test_must_be_empty out &&
t/t1800-hook.sh +4 -1
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \
+               sed -e "s/$quot//g" | \
+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
       test_cmp expect actual

'

Quoted 1 line

This does not require setting up a prerequisite for NonStop and the

technique

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

might make the MING code easier but adding a change from spawn to run.

This is still broken on NonStop. Is there any hope of a resolution?

So trying to execute an executable file consisting only of the line "#!/bad/path/no/spaces" causes NonStop to report "Permission denied"? That message text belongs to error code EACCES, not to EPERM ("Operation not permitted"), right?

That should be correct, although the OS Devs I spoke to about this said "EPERM". I am experimenting.

Quoted 3 lines

POSIX allows execve to return EACCES if the file to execute is not a regular file and executing that file type is not supported or if permissions are missing to one of its path components.

Part of the OS Dev's response was that POSIX is actually ambiguous on this point. Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it may actually be EACCESS - I will report back.

Quoted 15 lines

Either you have something called /bad that is not a regular file (e.g. a directory) -- then it's just a matter of changing the test to use a different supposedly non-existing filename, perhaps by creating and deleting a temporary file for just that purpose.

Or NonStop correctly returns ENOEXEC on the first execve(2) call in run-command.c and returns ENOACCES on the fallback with SHELL_PATH (default value /usr/coreutils/bin/bash), because you are not allowed to execute that shell. Then SHELL_PATH needs to be corrected.

Or valid shells need to be placed in some kind of allow list to be accepted in #!-lines, lest NonStop returns ENOACCES on them. Or NonStop is simply reporting a bogus error code for some reason. In those cases you probably need an execve) compat/ wrapper that corrects the error code.

Quoted 5 lines

Or I'm missing something here, which is a relatively safe bet. Anyway, depending on the cause of the "Permission denied" message, loosening the textual comparison in the test might not be enough. There may not be a point for end users to distinguish between "exec" vs. "run", but the silent_exec_failure feature of run-command depends on the error code being ENOENT.

I will report my debug findings.
--Randall

#6 lore raw

RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Quoted 80 lines · On Monday, May 22, 2023 4:49 PM, I wrote:
Quoted 42 lines · René Scharfe

Am 14.12.22 um 06:53 schrieb [email protected]:

Quoted 41 lines · On September 23, 2022 4:43 PM, I wrote:
Quoted 38 lines · On September 22, 2022 3:03 PM, I wrote:
Quoted 8 lines · On September 22, 2022 3:02 PM, I wrote:
Quoted 7 lines

Rc1 is looking good except for this test.

We get a diff as follows:

(quoted diff) +1 -1
-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
Quoted 8 lines
Quoted 8 lines

It looks like the pattern
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

A patch that might work is as follows:

t/t1800-hook.sh index renamed from t/t1800-hook.sh +0 -0

43fcb7c0bf..9a723631a2
100755

t/t1800-hook.sh +0 -0
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a

bad shebang' '

               -c core.hooksPath=bad-hooks \
               hook run test-hook >out 2>err &&
       test_must_be_empty out &&
t/t1800-hook.sh +4 -1
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \
+               sed -e "s/$quot//g" | \
+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
       test_cmp expect actual

'

Quoted 1 line

This does not require setting up a prerequisite for NonStop and the

technique

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

might make the MING code easier but adding a change from spawn to run.

This is still broken on NonStop. Is there any hope of a resolution?

So trying to execute an executable file consisting only of the line "#!/bad/path/no/spaces" causes NonStop to report "Permission denied"? That message text belongs to error code EACCES, not to EPERM ("Operation not permitted"), right?

That should be correct, although the OS Devs I spoke to about this said "EPERM". I am experimenting.

Quoted 3 lines

POSIX allows execve to return EACCES if the file to execute is not a regular file and executing that file type is not supported or if permissions are missing to one of its path components.

Part of the OS Dev's response was that POSIX is actually ambiguous on this point. Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it may actually be EACCESS - I will report back.

Quoted 11 lines

Either you have something called /bad that is not a regular file (e.g. a
directory) -- then it's just a matter of changing the test to use a different supposedly non-existing filename, perhaps by creating and deleting a temporary file for just that purpose.

Or NonStop correctly returns ENOEXEC on the first execve(2) call in run-command.c and returns ENOACCES on the fallback with SHELL_PATH (default value /usr/coreutils/bin/bash), because you are not allowed to execute that shell. Then SHELL_PATH needs to be corrected.

Quoted 4 lines

Or valid shells need to be placed in some kind of allow list to be accepted in #!-lines, lest NonStop returns ENOACCES on them. Or NonStop is simply reporting a bogus error code for some reason. In those cases you probably need an execve) compat/ wrapper that corrects the error

code.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

Or I'm missing something here, which is a relatively safe bet. Anyway, depending on the cause of the "Permission denied" message, loosening the textual comparison in the test might not be enough. There may not be a point for end users to distinguish between "exec" vs. "run", but the silent_exec_failure feature of run-command depends on the error code being

ENOENT.

I will report my debug findings.

NonStop actually does report EACCES, not EPERM. The comment at the front of run-command.c does describe the situation. The following is a potential fix:

run-command.c +1 -1
index 60c9419866..b76e117d35 100644
@@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
                        execve(argv.v[0], (char *const *) argv.v,
                               (char *const *) childenv);
 
-               if (errno == ENOENT) {
+               if (errno == ENOENT || errno == EACCES) {
                        if (cmd->silent_exec_failure)
                                child_die(CHILD_ERR_SILENT);
                        child_die(CHILD_ERR_ENOENT);

This does pass and should cover all POSIX interpretations.

Regards,
Randall

#7 lore raw

Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Am 22.05.23 um 23:13 schrieb [email protected]:

Quoted 10 lines · On Monday, May 22, 2023 4:49 PM, I wrote:
Quoted 9 lines · René Scharfe
Quoted 4 lines

So trying to execute an executable file consisting only of the line "#!/bad/path/no/spaces" causes NonStop to report "Permission denied"? That message text belongs to error code EACCES, not to EPERM ("Operation not permitted"), right?

That should be correct, although the OS Devs I spoke to about this said "EPERM". I am experimenting.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

POSIX allows execve to return EACCES if the file to execute is not a regular file and executing that file type is not supported or if permissions are missing to one of its path components.

Part of the OS Dev's response was that POSIX is actually ambiguous on this point. Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it may actually be EACCESS - I will report back.

In https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
I don't see how EACCES would be a valid response in this case. And it makes no intuitive sense -- which permission is missing in this situation?

That doesn't change the fact that this issue needs to be dealt with in Git somehow.

Quoted 2 lines

NonStop actually does report EACCES, not EPERM. The comment at the front of run-command.c does describe the situation.

Do you mean the one about EACCES being reported if a directory in $PATH is inaccessible in sane_execvp()? That does not apply here because "#!/bad/path/no/spaces" specifies an absolute path, so $PATH is not searched.

Quoted 16 lines

The following is a potential fix:

run-command.c +1 -1
index 60c9419866..b76e117d35 100644
@@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
                        execve(argv.v[0], (char *const *) argv.v,
                               (char *const *) childenv);
 
-               if (errno == ENOENT) {
+               if (errno == ENOENT || errno == EACCES) {
                        if (cmd->silent_exec_failure)
                                child_die(CHILD_ERR_SILENT);
                        child_die(CHILD_ERR_ENOENT);
Quoted 1 line

This does pass and should cover all POSIX interpretations.

That would misreport execution failures due to missing permissions (think e.g. "chmod 0 file") as "No such file or directory". So this should be only done if really needed, perhaps guarded by an access(2) check for verifying that EACCES is bogus, and only on affected platforms.

René

#8 lore raw

Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Am 04.06.23 um 14:13 schrieb René Scharfe:

Quoted 17 lines

Am 22.05.23 um 23:13 schrieb [email protected]:

Quoted 16 lines

The following is a potential fix:

run-command.c +1 -1
index 60c9419866..b76e117d35 100644
@@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
                        execve(argv.v[0], (char *const *) argv.v,
                               (char *const *) childenv);
 
-               if (errno == ENOENT) {
+               if (errno == ENOENT || errno == EACCES) {
                        if (cmd->silent_exec_failure)
                                child_die(CHILD_ERR_SILENT);
                        child_die(CHILD_ERR_ENOENT);
Quoted 7 lines
Quoted 1 line

This does pass and should cover all POSIX interpretations.

That would misreport execution failures due to missing permissions (think e.g. "chmod 0 file") as "No such file or directory". So this should be only done if really needed, perhaps guarded by an access(2) check for verifying that EACCES is bogus, and only on affected platforms.

Actually the difference is a bit more subtle. With that patch and silent_exec_failure on, missing permissions wouldn't be reported anymore, and with it off the eventual message command would change from:

                error_errno("cannot exec '%s'", cmd->args.v[0]);

to:

                error_errno("cannot run %s", cmd->args.v[0]);

So the actual errno-based message would be the same, unless its suppressed.

What's the significance of "run" and "exec" here? Why do we have both variants? Is it to tell apart errors of the actual execve(2) call from those in code leading up to it (e.g. when searching the executable in $PATH)? But at this point we are after the call, so why is ENOENT from execve(2) a "run" thing, not an "exec" thing?

René

#9 lore raw

Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison

Quoted 5 lines · René Scharfe

What's the significance of "run" and "exec" here? Why do we have both variants? Is it to tell apart errors of the actual execve(2) call from those in code leading up to it (e.g. when searching the executable in $PATH)? But at this point we are after the call, so why is ENOENT from execve(2) a "run" thing, not an "exec" thing?

I was reading output from

    $ git log --reverse -p -SNOENT 7e5d776854e.. run-command.c

45c0961c (run_command(): handle missing command errors more gracefully, 2009-01-28) explains how we use NOENT to tell between "we failed to run the command requested because it did not even exist" and "we failed to run the command and the reason why it failed is *not* because it did not exist" (the distinction matters to implement "run command X on $PATH"). To further that, 38f865c2 (run-command: treat inaccessible directories as ENOENT, 2012-03-30) and a7855083 (sane_execvp(): ignore non-directory on $PATH, 2012-07-31) dealt corner cases where entries on $PATH were unreadable or were non-directories, but the idea should be the same.

All of the above matters purely when we fail silently (because we expect only some directories on $PATH contain the command), and I suspect that the phrasing differences when we _do_ tell the human user what we failed to run does not matter all that much.

#10 lore raw

PATCH 1/2 t1800: loosen matching of error message for bad shebang

t1800.16 checks whether an attempt to run a hook script with a missing executable in its #! line fails and reports that error. The expected error message differs between platforms. The test handles two common variants, but on NonStop OS we get a third one: "fatal: cannot exec 'bad-hooks/test-hook': ...", which causes the test to fail there.

We don't really care about the specific message text all that much here. Use grep and a single regex with alternations to ascertain that we get an error message (fatal or otherwise) about the failed invocation of the hook, but don't bother checking if we get the right variant for the platform the test is running on or whether quoting is done. This looser check let's the test pass on NonStop OS.

---
 t/t1800-hook.sh | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
t/t1800-hook.sh +5 -15
index 3506f627b6..c156d6decc 100755
@@ -156,25 +156,15 @@ test_expect_success 'git hook run a hook with a bad shebang' '
 	mkdir bad-hooks &&
 	write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
 
-	# 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()
-	if test_have_prereq !MINGW
-	then
-		cat >expect <<-\EOF
-		fatal: cannot run bad-hooks/test-hook: ...
-		EOF
-	else
-		cat >expect <<-\EOF
-		error: cannot spawn bad-hooks/test-hook: ...
-		EOF
-	fi &&
 	test_expect_code 1 git \
 		-c core.hooksPath=bad-hooks \
 		hook run test-hook >out 2>err &&
 	test_must_be_empty out &&
-	sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
-	test_cmp expect actual
+
+	# 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
 '
 
 test_expect_success 'stdin to hooks' '

--
2.41.0

#12 lore raw

PATCH 2/2 run-command: report exec error even on ENOENT

In reply to Junio C Hamano

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".

---
Patch formatted with -U6 for easier review.

 run-command.c   | 14 +++-----------
 t/t1800-hook.sh |  2 +-
 2 files changed, 4 insertions(+), 12 deletions(-)
run-command.c +3 -11
index 60c9419866..758f8534da 100644
@@ -304,13 +304,12 @@ static int child_notifier = -1;
 
 enum child_errcode {
 	CHILD_ERR_CHDIR,
 	CHILD_ERR_DUP2,
 	CHILD_ERR_CLOSE,
 	CHILD_ERR_SIGPROCMASK,
-	CHILD_ERR_ENOENT,
 	CHILD_ERR_SILENT,
 	CHILD_ERR_ERRNO
 };
 
 struct child_err {
 	enum child_errcode err;
@@ -387,15 +386,12 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
 	case CHILD_ERR_CLOSE:
 		error_errno("close() in child failed");
 		break;
 	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:
 		error_errno("cannot exec '%s'", cmd->args.v[0]);
 		break;
 	}
@@ -843,19 +839,15 @@ int start_command(struct child_process *cmd)
 		execve(argv.v[1], (char *const *) argv.v + 1,
 		       (char *const *) childenv);
 		if (errno == ENOEXEC)
 			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)
 		error_errno("cannot fork() for %s", cmd->args.v[0]);
 	else if (cmd->clean_on_exit)
 		mark_child_for_cleanup(cmd->pid, cmd);
t/t1800-hook.sh +1 -1
index c156d6decc..8b0234cf2d 100755
@@ -161,13 +161,13 @@ test_expect_success 'git hook run a hook with a bad shebang' '
 		hook run test-hook >out 2>err &&
 	test_must_be_empty out &&
 
 	# 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' '
 	write_script .git/hooks/test-hook <<-\EOF &&
 	echo BEGIN stdin
 	cat

--
2.41.0

#11 lore raw

Re: [PATCH 1/2] t1800: loosen matching of error message for bad shebang

In reply to René Scharfe

t/t1800-hook.sh test_expect_success 'git hook run a hook with a bad shebang' ' · line 167

Quoted 4 lines · René Scharfe
t/t1800-hook.sh +4 -0
+	# 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

Looking great. Thanks.