( worktreePath: string, )
| 619 | * malformed. Caller can treat null as "not a valid worktree". |
| 620 | */ |
| 621 | export 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. |
no test coverage detected