Skip to content

Commit a34310f

Browse files
committed
Add a check for when the command is canceled by the program on Windows OS.
1 parent 9043584 commit a34310f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

modules/git/command.go

Lines changed: 13 additions & 1 deletion
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,7 +345,18 @@ func (c *Command) Run(opts *RunOpts) error {
344345
log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
345346
}
346347

347-
if err != nil && ctx.Err() != context.DeadlineExceeded {
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+
359+
if err != nil && ctx.Err() != context.DeadlineExceeded && ctx.Err() != context.Canceled {
348360
return err
349361
}
350362

0 commit comments

Comments
 (0)