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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 package git
2
3 import "bytes"
4 import "os/exec"
5
6 // RunInput runs a git command in the Repo, passing input on stdin, and returnin g
7 // the stdout and success (i.e. did the git command return 0?)
8 func (r *Repo) RunInput(input string, cmd ...string) (string, bool) {
9 ex := exec.Command("git", cmd...)
10 ex.Dir = r.Path
11 ex.Stdin = bytes.NewBufferString(input)
12 out, err := ex.Output()
13 if err == nil {
14 return string(out), true
15 } else if _, ok := err.(*exec.ExitError); ok {
16 return string(out), false
17 } else {
18 panic(err)
19 }
20 }
21
22 // Run runs a git command in the Repo, with no input, returning the stdout and
23 // success.
24 func (r *Repo) Run(cmd ...string) (string, bool) {
25 return r.RunInput("", cmd...)
26 }
27
28 // RunOk runs a git command in the repo with no input, and returns its success
29 // (did it exit 0?)
30 func (r *Repo) RunOk(cmd ...string) bool {
31 _, ok := r.Run(cmd...)
32 return ok
33 }
34
35 // RunOutput runs a git command in the repo with no input, and returns its
36 // stdout
37 func (r *Repo) RunOutput(cmd ...string) string {
38 out, _ := r.Run(cmd...)
39 return out
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698