MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / computeDefaultBranch

Function computeDefaultBranch

source code/utils/git/gitFilesystem.ts:546–568  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

544}
545
546async function computeDefaultBranch(): Promise<string> {
547 const gitDir = await resolveGitDir()
548 if (!gitDir) {
549 return 'main'
550 }
551 // refs/remotes/ lives in commonDir, not the per-worktree gitDir
552 const commonDir = (await getCommonDir(gitDir)) ?? gitDir
553 const branchFromSymref = await readRawSymref(
554 commonDir,
555 'refs/remotes/origin/HEAD',
556 'refs/remotes/origin/',
557 )
558 if (branchFromSymref) {
559 return branchFromSymref
560 }
561 for (const candidate of ['main', 'master']) {
562 const sha = await resolveRef(commonDir, `refs/remotes/origin/${candidate}`)
563 if (sha) {
564 return candidate
565 }
566 }
567 return 'main'
568}
569
570export function getCachedBranch(): Promise<string> {
571 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