| 180 | } |
| 181 | |
| 182 | func RunGitPush(ctx context.Context, path, remoteName, branchName string) error { |
| 183 | cmd := exec.CommandContext(ctx, "git", "-C", path, "push", remoteName, branchName) |
| 184 | if out, err := cmd.CombinedOutput(); err != nil { |
| 185 | var execErr *exec.ExitError |
| 186 | if errors.As(err, &execErr) { |
| 187 | return fmt.Errorf("git push failed: %s(%s)", string(out), string(execErr.Stderr)) |
| 188 | } |
| 189 | return fmt.Errorf("git push failed: %s(%w)", string(out), err) |
| 190 | } |
| 191 | return nil |
| 192 | } |
| 193 | |
| 194 | func InferGitRepoRoot(path string) (string, error) { |
| 195 | cmd := exec.Command("git", "-C", path, "rev-parse", "--show-cdup") |