Fix the issue with error message logging for the check-attr command on Windows OS. (#34035) (#34036)

Backport #34035 by charles7668

Close #34022 , #33550 

This error message always appears when using the `check-attr` command,
even though it works correctly.
The issue occurs when the stdin writer is closed, so I added a special
case to handle and check the error message when the exit code is 1.

Co-authored-by: charles <30816317+charles7668@users.noreply.github.com>
This commit is contained in:
Giteabot 2025-03-27 17:50:57 +08:00 committed by GitHub
parent 690e810bcc
commit e46f9ff534
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -350,9 +350,10 @@ func (c *Command) Run(opts *RunOpts) error {
// We need to check if the context is canceled by the program on Windows.
// This is because Windows does not have signal checking when terminating the process.
// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
// `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
if runtime.GOOS == "windows" &&
err != nil &&
err.Error() == "" &&
(err.Error() == "" || err.Error() == "exit status 1") &&
cmd.ProcessState.ExitCode() == 1 &&
ctx.Err() == context.Canceled {
return ctx.Err()