MCPcopy
hub / github.com/git-lfs/git-lfs / Output

Function Output

subprocess/subprocess.go:92–114  ·  view source on GitHub ↗
(cmd *Cmd)

Source from the content-addressed store, hash-verified

90}
91
92func Output(cmd *Cmd) (string, error) {
93 out, err := cmd.Output()
94
95 if exitError, ok := err.(*exec.ExitError); ok {
96 errorOutput := strings.TrimSpace(string(exitError.Stderr))
97 if errorOutput == "" {
98 // some commands might write nothing to stderr but something to stdout in error-conditions, in which case, we'll use that
99 // in the error string
100 errorOutput = strings.TrimSpace(string(out))
101 }
102
103 ran := cmd.Path
104 if len(cmd.Args) > 1 {
105 ran = fmt.Sprintf("%s %s", cmd.Path, quotedArgs(cmd.Args[1:]))
106 }
107 formattedErr := errors.New(tr.Tr.Get("error running %s: '%s' '%s'", ran, errorOutput, strings.TrimSpace(exitError.Error())))
108
109 // return "" as output in error case, for callers that don't care about errors but rely on "" returned, in-case stdout != ""
110 return "", formattedErr
111 }
112
113 return strings.Trim(string(out), " \n"), err
114}
115
116var shellWordRe = regexp.MustCompile(`\A[A-Za-z0-9_@/.-]+\z`)
117

Callers 2

gitConfigMethod · 0.92
SimpleExecFunction · 0.85

Calls 4

quotedArgsFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.65
OutputMethod · 0.45

Tested by

no test coverage detected