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

Method Output

git/command.go:37–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

TestOutputFunction · 0.95

Calls 2

OutputMethod · 0.65
ExitCodeMethod · 0.65

Tested by 1

TestOutputFunction · 0.76