MCPcopy
hub / github.com/codeaashu/claude-code / readWorktreeHeadSha

Function readWorktreeHeadSha

src/utils/git/gitFilesystem.ts:619–640  ·  view source on GitHub ↗
(
  worktreePath: string,
)

Source from the content-addressed store, hash-verified

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