MCPcopy Create free account
hub / github.com/cli/cli / Output

Method Output

git/command.go:35–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

Calls 2

OutputMethod · 0.65
ExitCodeMethod · 0.65

Tested by 2