gitOutput runs a git command in dir and returns its trimmed stdout.
(ctx context.Context, dir string, args ...string)
| 402 | |
| 403 | // gitOutput runs a git command in dir and returns its trimmed stdout. |
| 404 | func gitOutput(ctx context.Context, dir string, args ...string) (string, error) { |
| 405 | cmd := exec.CommandContext(ctx, "git", append([]string{"-C", dir}, args...)...) |
| 406 | var stdout, stderr bytes.Buffer |
| 407 | cmd.Stdout = &stdout |
| 408 | cmd.Stderr = &stderr |
| 409 | if err := cmd.Run(); err != nil { |
| 410 | if msg := strings.TrimSpace(stderr.String()); msg != "" { |
| 411 | return "", fmt.Errorf("%w: %s", err, msg) |
| 412 | } |
| 413 | return "", err |
| 414 | } |
| 415 | return strings.TrimSpace(stdout.String()), nil |
| 416 | } |
| 417 | |
| 418 | // gh runs a GitHub CLI command in dir, surfacing its stderr on failure. |
| 419 | func gh(ctx context.Context, dir string, args ...string) error { |