MCPcopy
hub / github.com/claude-code-best/claude-code / computeDefaultBranch

Function computeDefaultBranch

src/utils/git/gitFilesystem.ts:544–566  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

542}
543
544async 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
568export function getCachedBranch(): Promise<string> {
569 return gitWatcher.get('branch', computeBranch)

Callers

nothing calls this directly

Calls 4

resolveGitDirFunction · 0.85
getCommonDirFunction · 0.85
readRawSymrefFunction · 0.85
resolveRefFunction · 0.85

Tested by

no test coverage detected