fix: invalidate worktree list cache after create and remove (#973)
* fix: invalidate worktree list cache after create and remove After creating or removing a worktree, the list cache was not cleared, so the UI would show stale data for up to 30 seconds. * fix: normalize cache key in removeProjectWorktree Greptile review caught that project.path was used raw while the cache stores normalizePath(project.path), so the delete could silently miss on paths with trailing slashes or backslashes.
This commit is contained in:
@@ -246,7 +246,6 @@ export async function listProjectWorktrees(project: ProjectRef): Promise<Worktre
|
||||
projectDirectory: metadataProjectDirectory,
|
||||
branch: branch,
|
||||
label: branch || name || deriveSdkWorktreeNameFromDirectory(worktreePath),
|
||||
// Phase 1 canonical fields
|
||||
worktreeRoot: canonical.worktreeRoot,
|
||||
worktreeStatus: canonical.worktreeStatus,
|
||||
headState: canonical.headState,
|
||||
@@ -307,7 +306,6 @@ export async function createWorktree(project: ProjectRef, args: CreateWorktreeAr
|
||||
projectDirectory: metadataProjectDirectory,
|
||||
branch: returnedBranch,
|
||||
label: returnedBranch || returnedName,
|
||||
// Phase 1 canonical fields
|
||||
worktreeRoot: normalizePath(returnedPath),
|
||||
worktreeStatus: 'ready',
|
||||
headState: returnedBranch ? 'branch' : 'unborn',
|
||||
@@ -316,6 +314,8 @@ export async function createWorktree(project: ProjectRef, args: CreateWorktreeAr
|
||||
|
||||
markWorktreeBootstrapPending(metadata.path);
|
||||
|
||||
_worktreeListCache.delete(projectDirectory);
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@@ -345,6 +345,8 @@ export async function removeProjectWorktree(project: ProjectRef, worktree: Workt
|
||||
|
||||
clearWorktreeBootstrapState(worktree.path);
|
||||
|
||||
_worktreeListCache.delete(normalizePath(project.path));
|
||||
|
||||
const branchName = (worktree.branch || '').replace(/^refs\/heads\//, '').trim();
|
||||
if (deleteRemote && branchName) {
|
||||
await deleteRemoteBranch(projectDirectory, { branch: branchName, remote: remoteName }).catch(() => undefined);
|
||||
|
||||
Reference in New Issue
Block a user