| 9 | "strings" |
| 10 | ) |
| 11 | |
| 12 | // runGit runs a git command and, on failure, returns git's own stderr |
| 13 | // message (e.g. "not a git repository", "dubious ownership") instead of |
| 14 | // just the bare exit status. |
| 15 | func runGit(args ...string) ([]byte, error) { |
| 16 | cmd := exec.Command("git", args...) |
| 17 | var stderr bytes.Buffer |
| 18 | cmd.Stderr = &stderr |
| 19 | |
| 20 | out, err := cmd.Output() |
| 21 | if err != nil { |
| 22 | msg := strings.TrimSpace(stderr.String()) |
| 23 | if msg == "" { |
| 24 | msg = err.Error() |
| 25 | } |
| 26 | return nil, fmt.Errorf("%s", msg) |
| 27 | } |
| 28 | return out, nil |
| 29 | } |