Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: go/src/infra/libs/git/run.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+}

Powered by Google App Engine
This is Rietveld 408576698