diff --git a/git/command.go b/git/command.go index 8065ffd86..c4614d086 100644 --- a/git/command.go +++ b/git/command.go @@ -43,10 +43,21 @@ func (gc *Command) Output() ([]byte, error) { out, err := run.PrepareCmd(gc.Cmd).Output() if err != nil { ge := GitError{err: err} + + // In real implementation, this should be an exec.ExitError, as below, + // but the tests use a different type because exec.ExitError are difficult + // to create. We want to get the exit code and stderr, but stderr + // is not a method and so tests can't access it. + // THIS MEANS THAT TESTS WILL NOT CORRECTLY HAVE STDERR SET, + // but at least tests can get the exit code. + var exitErrorWithExitCode errWithExitCode + if errors.As(err, &exitErrorWithExitCode) { + ge.ExitCode = exitErrorWithExitCode.ExitCode() + } + var exitError *exec.ExitError if errors.As(err, &exitError) { ge.Stderr = string(exitError.Stderr) - ge.ExitCode = exitError.ExitCode() } err = &ge } diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index cfe6193c9..51cbfa724 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -1304,9 +1304,9 @@ func Test_createRun(t *testing.T) { }, customPushDestination: true, cmdStubs: func(cs *run.CommandStubber) { - cs.Register("git rev-parse --abbrev-ref feature@{push}", 0, "") - cs.Register("git config remote.pushDefault", 0, "") - cs.Register("git config push.default", 0, "") + cs.Register("git rev-parse --abbrev-ref feature@{push}", 1, "fatal: not a git repository (or any of the parent directories): .git") + cs.Register("git config remote.pushDefault", 1, "") + cs.Register("git config push.default", 1, "") }, expectedOut: "https://github.com/OWNER/REPO/pull/12\n", },