summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useGitBranchName.ts
diff options
context:
space:
mode:
authorScott Densmore <[email protected]>2025-05-30 21:08:56 -0700
committerGitHub <[email protected]>2025-05-30 21:08:56 -0700
commitbda7ec94df2074d006058ff9f739edc6e3996214 (patch)
treed1e7ab4bbe4c64779d371e93e64ae0b7d9e05424 /packages/cli/src/ui/hooks/useGitBranchName.ts
parent1468047081d330bd36e98380d6eaa8588653f78e (diff)
Fix: Update git branch watcher to use .git/logs/HEAD (#643)
Diffstat (limited to 'packages/cli/src/ui/hooks/useGitBranchName.ts')
-rw-r--r--packages/cli/src/ui/hooks/useGitBranchName.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/packages/cli/src/ui/hooks/useGitBranchName.ts b/packages/cli/src/ui/hooks/useGitBranchName.ts
index 6b7b2769..463c773f 100644
--- a/packages/cli/src/ui/hooks/useGitBranchName.ts
+++ b/packages/cli/src/ui/hooks/useGitBranchName.ts
@@ -37,14 +37,17 @@ export function useGitBranchName(cwd: string): string | undefined {
useEffect(() => {
fetchBranchName(); // Initial fetch
- const gitHeadPath = path.join(cwd, '.git', 'HEAD');
+ const gitLogsHeadPath = path.join(cwd, '.git', 'logs', 'HEAD');
let watcher: fs.FSWatcher | undefined;
const setupWatcher = async () => {
try {
- await fsPromises.access(gitHeadPath, fs.constants.F_OK);
- watcher = fs.watch(gitHeadPath, (eventType) => {
- if (eventType === 'change') {
+ // Check if .git/logs/HEAD exists, as it might not in a new repo or orphaned head
+ await fsPromises.access(gitLogsHeadPath, fs.constants.F_OK);
+ watcher = fs.watch(gitLogsHeadPath, (eventType: string) => {
+ // Changes to .git/logs/HEAD (appends) indicate HEAD has likely changed
+ if (eventType === 'change' || eventType === 'rename') {
+ // Handle rename just in case
fetchBranchName();
}
});