| 36 | } |
| 37 | |
| 38 | func (gc *Command) Output() ([]byte, error) { |
| 39 | gc.Stdout = nil |
| 40 | gc.Stderr = nil |
| 41 | // This is a hack in order to not break the hundreds of |
| 42 | // existing tests that rely on `run.PrepareCmd` to be invoked. |
| 43 | out, err := run.PrepareCmd(gc.Cmd).Output() |
| 44 | if err != nil { |
| 45 | ge := GitError{err: err} |
| 46 | |
| 47 | // In real implementation, this should be an exec.ExitError, as below, |
| 48 | // but the tests use a different type because exec.ExitError are difficult |
| 49 | // to create. We want to get the exit code and stderr, but stderr |
| 50 | // is not a method and so tests can't access it. |
| 51 | // THIS MEANS THAT TESTS WILL NOT CORRECTLY HAVE STDERR SET, |
| 52 | // but at least tests can get the exit code. |
| 53 | var exitErrorWithExitCode errWithExitCode |
| 54 | if errors.As(err, &exitErrorWithExitCode) { |
| 55 | ge.ExitCode = exitErrorWithExitCode.ExitCode() |
| 56 | } |
| 57 | |
| 58 | var exitError *exec.ExitError |
| 59 | if errors.As(err, &exitError) { |
| 60 | ge.Stderr = string(exitError.Stderr) |
| 61 | } |
| 62 | err = &ge |
| 63 | } |
| 64 | return out, err |
| 65 | } |
| 66 | |
| 67 | func (gc *Command) setRepoDir(repoDir string) { |
| 68 | for i, arg := range gc.Args { |