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