Skip to content

Commit 423372d

Browse files
authored
Add a check for when the command is canceled by the program on Window… (#29538)
Close #29509 Windows, unlike Linux, does not have signal-specified exit codes. Therefore, we should add a Windows-specific check for Windows. If we don't do this, the logs will always show a failed status, even though the command actually works correctly. If you check the Go source code in exec_windows.go, you will see that it always returns exit code 1. ![image](https://github.com/go-gitea/gitea/assets/30816317/9dfd7c70-9995-47d9-9641-db793f58770c) The exit code 1 does not exclusively signify a SIGNAL KILL; it can indicate any issue that occurs when a program fails.
1 parent e650f64 commit 423372d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

modules/git/command.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"io"
1313
"os"
1414
"os/exec"
15+
"runtime"
1516
"strings"
1617
"time"
1718

@@ -344,6 +345,17 @@ func (c *Command) Run(opts *RunOpts) error {
344345
log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
345346
}
346347

348+
// We need to check if the context is canceled by the program on Windows.
349+
// This is because Windows does not have signal checking when terminating the process.
350+
// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
351+
if runtime.GOOS == "windows" &&
352+
err != nil &&
353+
err.Error() == "" &&
354+
cmd.ProcessState.ExitCode() == 1 &&
355+
ctx.Err() == context.Canceled {
356+
return ctx.Err()
357+
}
358+
347359
if err != nil && ctx.Err() != context.DeadlineExceeded {
348360
return err
349361
}

0 commit comments

Comments
 (0)