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

Function findRemoteBase

source code/utils/git.ts:564–605  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

562 * Priority: tracking branch > origin/main > origin/staging > origin/master
563 */
564export async function findRemoteBase(): Promise<string | null> {
565 // First try: get the tracking branch for the current branch
566 const { stdout: trackingBranch, code: trackingCode } = await execFileNoThrow(
567 gitExe(),
568 ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'],
569 { preserveOutputOnError: false },
570 )
571
572 if (trackingCode === 0 && trackingBranch.trim()) {
573 return trackingBranch.trim()
574 }
575
576 // Second try: check for common default branch names on origin
577 const { stdout: remoteRefs, code: remoteCode } = await execFileNoThrow(
578 gitExe(),
579 ['remote', 'show', 'origin', '--', 'HEAD'],
580 { preserveOutputOnError: false },
581 )
582
583 if (remoteCode === 0) {
584 // Parse the default branch from remote show output
585 const match = remoteRefs.match(/HEAD branch: (\S+)/)
586 if (match && match[1]) {
587 return `origin/${match[1]}`
588 }
589 }
590
591 // Third try: check which common branches exist
592 const candidates = ['origin/main', 'origin/staging', 'origin/master']
593 for (const candidate of candidates) {
594 const { code } = await execFileNoThrow(
595 gitExe(),
596 ['rev-parse', '--verify', candidate],
597 { preserveOutputOnError: false },
598 )
599 if (code === 0) {
600 return candidate
601 }
602 }
603
604 return null
605}
606
607/**
608 * Check if we're in a shallow clone by looking for <gitDir>/shallow.

Callers 1

preserveGitStateForIssueFunction · 0.85

Calls 1

execFileNoThrowFunction · 0.85

Tested by

no test coverage detected