()
| 542 | } |
| 543 | |
| 544 | async function computeDefaultBranch(): Promise<string> { |
| 545 | const gitDir = await resolveGitDir() |
| 546 | if (!gitDir) { |
| 547 | return 'main' |
| 548 | } |
| 549 | // refs/remotes/ lives in commonDir, not the per-worktree gitDir |
| 550 | const commonDir = (await getCommonDir(gitDir)) ?? gitDir |
| 551 | const branchFromSymref = await readRawSymref( |
| 552 | commonDir, |
| 553 | 'refs/remotes/origin/HEAD', |
| 554 | 'refs/remotes/origin/', |
| 555 | ) |
| 556 | if (branchFromSymref) { |
| 557 | return branchFromSymref |
| 558 | } |
| 559 | for (const candidate of ['main', 'master']) { |
| 560 | const sha = await resolveRef(commonDir, `refs/remotes/origin/${candidate}`) |
| 561 | if (sha) { |
| 562 | return candidate |
| 563 | } |
| 564 | } |
| 565 | return 'main' |
| 566 | } |
| 567 | |
| 568 | export function getCachedBranch(): Promise<string> { |
| 569 | return gitWatcher.get('branch', computeBranch) |
nothing calls this directly
no test coverage detected