remoteDefaultBranch resolves origin's default branch, falling back to "main" when origin/HEAD is not configured locally.
(ctx context.Context)
| 325 | // remoteDefaultBranch resolves origin's default branch, falling back to "main" |
| 326 | // when origin/HEAD is not configured locally. |
| 327 | func remoteDefaultBranch(ctx context.Context) string { |
| 328 | out, err := runGit(ctx, "symbolic-ref", "--short", "refs/remotes/origin/HEAD") |
| 329 | if err != nil { |
| 330 | fmt.Fprintf(os.Stderr, |
| 331 | "warning: origin/HEAD is not set; assuming default branch is %q — "+ |
| 332 | "run 'git remote set-head origin -a' if the real default differs\n", "main") |
| 333 | return "main" |
| 334 | } |
| 335 | return strings.TrimPrefix(strings.TrimSpace(out), "origin/") |
| 336 | } |
| 337 | |
| 338 | func revParse(ctx context.Context, ref string) (string, error) { |
| 339 | out, err := runGit(ctx, "rev-parse", ref) |
no test coverage detected