| Index: go/src/infra/libs/git/run.go
|
| diff --git a/go/src/infra/libs/git/run.go b/go/src/infra/libs/git/run.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..41c017bf8aabf04fda6f5259cbacc5b7b759aabf
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/git/run.go
|
| @@ -0,0 +1,40 @@
|
| +package git
|
| +
|
| +import "bytes"
|
| +import "os/exec"
|
| +
|
| +// RunInput runs a git command in the Repo, passing input on stdin, and returning
|
| +// the stdout and success (i.e. did the git command return 0?)
|
| +func (r *Repo) RunInput(input string, cmd ...string) (string, bool) {
|
| + ex := exec.Command("git", cmd...)
|
| + ex.Dir = r.Path
|
| + ex.Stdin = bytes.NewBufferString(input)
|
| + out, err := ex.Output()
|
| + if err == nil {
|
| + return string(out), true
|
| + } else if _, ok := err.(*exec.ExitError); ok {
|
| + return string(out), false
|
| + } else {
|
| + panic(err)
|
| + }
|
| +}
|
| +
|
| +// Run runs a git command in the Repo, with no input, returning the stdout and
|
| +// success.
|
| +func (r *Repo) Run(cmd ...string) (string, bool) {
|
| + return r.RunInput("", cmd...)
|
| +}
|
| +
|
| +// RunOk runs a git command in the repo with no input, and returns its success
|
| +// (did it exit 0?)
|
| +func (r *Repo) RunOk(cmd ...string) bool {
|
| + _, ok := r.Run(cmd...)
|
| + return ok
|
| +}
|
| +
|
| +// RunOutput runs a git command in the repo with no input, and returns its
|
| +// stdout
|
| +func (r *Repo) RunOutput(cmd ...string) string {
|
| + out, _ := r.Run(cmd...)
|
| + return out
|
| +}
|
|
|