@@ -7,11 +7,9 @@ package git
77import (
88 "bytes"
99 "context"
10- "errors"
1110 "fmt"
1211 "io"
1312 "os"
14- "os/exec"
1513 "strconv"
1614 "strings"
1715 "time"
@@ -33,9 +31,6 @@ const DefaultTimeout = time.Minute
3331// variables and working directory. If the context does not already have a
3432// deadline, DefaultTimeout will be applied automatically.
3533func gitCmd (ctx context.Context , dir string , args []string , envs []string ) (* run.Command , context.CancelFunc ) {
36- if ctx == nil {
37- ctx = context .Background ()
38- }
3934 cancel := func () {}
4035
4136 // Apply default timeout if the context doesn't already have a deadline.
@@ -109,13 +104,10 @@ func gitRun(ctx context.Context, dir string, args []string, envs []string) ([]by
109104
110105// gitPipeline executes a git command in the given directory, streaming stdout
111106// to the given writer. If stderr writer is provided and the command fails,
112- // stderr content extracted from the error is written to it. stdin is optional.
113- func gitPipeline (ctx context.Context , dir string , args []string , envs []string , stdout , stderr io.Writer , stdin io. Reader ) error {
107+ // stderr content extracted from the error is written to it.
108+ func gitPipeline (ctx context.Context , dir string , args []string , envs []string , stdout , stderr io.Writer ) error {
114109 cmd , cancel := gitCmd (ctx , dir , args , envs )
115110 defer cancel ()
116- if stdin != nil {
117- cmd = cmd .Input (stdin )
118- }
119111
120112 var buf * bytes.Buffer
121113 w := stdout
@@ -216,15 +208,10 @@ func mapContextError(err error, ctx context.Context) error {
216208}
217209
218210// isExitStatus reports whether err represents a specific process exit status
219- // code. It handles both the bare "exit status N" format and the
220- // "exit status N: <stderr>" format produced by sourcegraph/run.
211+ // code, using the run.ExitCoder interface provided by sourcegraph/run.
221212func isExitStatus (err error , code int ) bool {
222- if err == nil {
223- return false
224- }
225- prefix := fmt .Sprintf ("exit status %d" , code )
226- msg := err .Error ()
227- return msg == prefix || strings .HasPrefix (msg , prefix + ":" )
213+ exitCoder , ok := err .(run.ExitCoder )
214+ return ok && exitCoder .ExitCode () == code
228215}
229216
230217// extractStderr attempts to extract the stderr portion from a sourcegraph/run
@@ -233,10 +220,6 @@ func extractStderr(err error) string {
233220 if err == nil {
234221 return ""
235222 }
236- var exitErr * exec.ExitError
237- if errors .As (err , & exitErr ) && len (exitErr .Stderr ) > 0 {
238- return string (exitErr .Stderr )
239- }
240223 msg := err .Error ()
241224 // sourcegraph/run error format: "exit status N: <stderr>"
242225 if idx := strings .Index (msg , ": " ); idx >= 0 && strings .HasPrefix (msg , "exit status" ) {
0 commit comments