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

Function readWorktreeHeadSha

source code/utils/git/gitFilesystem.ts:621–642  ·  view source on GitHub ↗
(
  worktreePath: string,
)

Source from the content-addressed store, hash-verified

619 * malformed. Caller can treat null as "not a valid worktree".
620 */
621export async function readWorktreeHeadSha(
622 worktreePath: string,
623): Promise<string | null> {
624 let gitDir: string
625 try {
626 const ptr = (await readFile(join(worktreePath, '.git'), 'utf-8')).trim()
627 if (!ptr.startsWith('gitdir:')) {
628 return null
629 }
630 gitDir = resolve(worktreePath, ptr.slice('gitdir:'.length).trim())
631 } catch {
632 return null
633 }
634 const head = await readGitHead(gitDir)
635 if (!head) {
636 return null
637 }
638 if (head.type === 'branch') {
639 return resolveRef(gitDir, `refs/heads/${head.name}`)
640 }
641 return head.sha
642}
643
644/**
645 * Read the remote origin URL for an arbitrary directory via .git/config.

Callers 1

getOrCreateWorktreeFunction · 0.85

Calls 4

readFileFunction · 0.85
readGitHeadFunction · 0.85
resolveRefFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected