Skip to content

Commit 8503b35

Browse files
authored
batches: Don't let stderr clutter git output (#785)
We parse lots of the things that git outputs, so having stderr randonly interfere with the output breaks that parsing. Since we can still get stderr from the exiterror, I don't think this is a regression at all in debuggability. This was found on k8s where parsing the patch would fail on a particular repo. Turns out git logged a warning.
1 parent 4723b4b commit 8503b35

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • internal/batches/workspace

internal/batches/workspace/git.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ func runGitCmd(ctx context.Context, dir string, args ...string) ([]byte, error)
2525
"GIT_COMMITTER_EMAIL=batch-changes@sourcegraph.com",
2626
}
2727
cmd.Dir = dir
28-
out, err := cmd.CombinedOutput()
28+
out, err := cmd.Output()
2929
if err != nil {
30-
return out, errors.Wrapf(err, "'git %s' failed: %s", strings.Join(args, " "), out)
30+
if exitErr, ok := err.(*exec.ExitError); ok {
31+
return out, errors.Wrapf(err, "'git %s' failed: %s", strings.Join(args, " "), string(exitErr.Stderr))
32+
}
33+
return out, errors.Wrapf(err, "'git %s' failed: %s", strings.Join(args, " "), string(out))
3134
}
3235
return out, nil
3336
}

0 commit comments

Comments
 (0)