threads / bug / 58497

[BUG] Git 2.28.0-rc1 t1800 message text comparison

Subject: [BUG] Git 2.28.0-rc1 t1800 message text comparison

## tl;dr

13 messages between Sep 22, 2022 and Jun 12, 2023.

replies: 12people: 3as markdown or json

rsbecker@nexbridge.com· Sep 22, 2022, 19:01 UTC · lore
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

rsbecker@nexbridge.com· Sep 22, 2022, 19:02 UTC · re: rsbecker@nexbridge.com · lore

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

On September 22, 2022 3:02 PM, I wrote:
Show 15 quoted lines
>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.
The subject should have been 2.38.0, not 2.28.0.
rsbecker@nexbridge.com· Sep 23, 2022, 20:43 UTC · re: rsbecker@nexbridge.com · lore

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

On September 22, 2022 3:03 PM, I wrote:
Show 16 quoted lines
>On September 22, 2022 3:02 PM, I wrote:
>>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.
A patch that might work is as follows:
diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index 43fcb7c0bf..9a723631a2 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -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
rsbecker@nexbridge.com· Dec 14, 2022, 05:53 UTC · re: rsbecker@nexbridge.com · lore

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

On September 23, 2022 4:43 PM, I wrote:
Show 38 quoted lines
>On September 22, 2022 3:03 PM, I wrote:
>>On September 22, 2022 3:02 PM, I wrote:
>>>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.
>
>A patch that might work is as follows:
>
>diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 43fcb7c0bf..9a723631a2
>100755
>--- a/t/t1800-hook.sh
>+++ b/t/t1800-hook.sh
>@@ -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.
This is still broken on NonStop. Is there any hope of a resolution?

Thanks, Randall

René Scharfe· May 22, 2023, 20:39 UTC · re: rsbecker@nexbridge.com · lore

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

Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
Show 43 quoted lines
> On September 23, 2022 4:43 PM, I wrote:
>> On September 22, 2022 3:03 PM, I wrote:
>>> On September 22, 2022 3:02 PM, I wrote:
>>>> 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.
>>
>> A patch that might work is as follows:
>>
>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 43fcb7c0bf..9a723631a2
>> 100755
>> --- a/t/t1800-hook.sh
>> +++ b/t/t1800-hook.sh
>> @@ -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.
>
> 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é
rsbecker@nexbridge.com· May 22, 2023, 20:49 UTC · re: René Scharfe · lore

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

On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
Show 50 quoted lines
>Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
>> On September 23, 2022 4:43 PM, I wrote:
>>> On September 22, 2022 3:03 PM, I wrote:
>>>> On September 22, 2022 3:02 PM, I wrote:
>>>>> 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.
>>>
>>> A patch that might work is as follows:
>>>
>>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index
>>> 43fcb7c0bf..9a723631a2
>>> 100755
>>> --- a/t/t1800-hook.sh
>>> +++ b/t/t1800-hook.sh
>>> @@ -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.
>>
>> 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.
>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.
Show 20 quoted 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.
>
>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

rsbecker@nexbridge.com· May 22, 2023, 21:13 UTC · re: rsbecker@nexbridge.com · lore

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

On Monday, May 22, 2023 4:49 PM, I wrote:
Show 88 quoted lines
>On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
>>Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
>>> On September 23, 2022 4:43 PM, I wrote:
>>>> On September 22, 2022 3:03 PM, I wrote:
>>>>> On September 22, 2022 3:02 PM, I wrote:
>>>>>> 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.
>>>>
>>>> A patch that might work is as follows:
>>>>
>>>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index
>>>> 43fcb7c0bf..9a723631a2
>>>> 100755
>>>> --- a/t/t1800-hook.sh
>>>> +++ b/t/t1800-hook.sh
>>>> @@ -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.
>>>
>>> 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.
>
>>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.
>
>>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.
>
>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:
diff --git a/run-command.c b/run-command.c
index 60c9419866..b76e117d35 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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
René Scharfe· Jun 4, 2023, 12:13 UTC · re: rsbecker@nexbridge.com · lore

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

Am 22.05.23 um 23:13 schrieb rsbecker@nexbridge.com:
Show 17 quoted lines
> On Monday, May 22, 2023 4:49 PM, I wrote:
>> On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
>>> 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.
>>
>>> 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.

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

Show 17 quoted lines
> The following is a potential fix:
>
> diff --git a/run-command.c b/run-command.c
> index 60c9419866..b76e117d35 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -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.

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é
René Scharfe· Jun 4, 2023, 20:55 UTC · re: René Scharfe · lore

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

Am 04.06.23 um 14:13 schrieb René Scharfe:
Show 24 quoted lines
> Am 22.05.23 um 23:13 schrieb rsbecker@nexbridge.com:
>> The following is a potential fix:
>>
>> diff --git a/run-command.c b/run-command.c
>> index 60c9419866..b76e117d35 100644
>> --- a/run-command.c
>> +++ b/run-command.c
>> @@ -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.
>
> 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é
Junio C Hamano· Jun 6, 2023, 00:31 UTC · re: René Scharfe · lore

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

René Scharfe <l.s.r@web.de> writes:
Show 5 quoted lines
> 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.

René Scharfe· Jun 10, 2023, 14:51 UTC · re: Junio C Hamano · lore

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

Reported-by: Randall S. Becker <randall.becker@nexbridge.ca>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t1800-hook.sh | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index 3506f627b6..c156d6decc 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -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
Junio C Hamano· Jun 12, 2023, 18:01 UTC · re: René Scharfe · lore

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

René Scharfe <l.s.r@web.de> writes:
> +	# 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.
René Scharfe· Jun 10, 2023, 14:51 UTC · re: Junio C Hamano · lore

[PATCH 2/2] 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>
---
Patch formatted with -U6 for easier review.
 run-command.c   | 14 +++-----------
 t/t1800-hook.sh |  2 +-
 2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/run-command.c b/run-command.c
index 60c9419866..758f8534da 100644
--- a/run-command.c
+++ b/run-command.c
@@ -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);
diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index c156d6decc..8b0234cf2d 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -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

← back to recent threads