| OLD | NEW |
| (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 } |
| OLD | NEW |