585
*/
586
async cleanupWorktreeOnArchive(sessionUri: URI, sessionId: string): Promise<void> {
587
>
return this._sequencer.queue(sessionId, () => this._cleanupWorktreeOnArchive(sessionUri, sessionId));
worktreeIsolation.ts
588
>
}
589
590
private async _cleanupWorktreeOnArchive(sessionUri: URI, sessionId: string): Promise<void> {
591
>
const meta = await this._readWorktreeMetadata(sessionUri).catch(() => undefined);
worktreeIsolation.ts
592
>
if (!meta?.worktreePath || !meta.repositoryRoot) {
593
return;
594
}
596
>
597
>
// Skip if the worktree directory is already gone — nothing to clean.
598
>
try {
599
>
await fs.access(worktreePath.fsPath);
600
>
} catch {
601
this._createdWorktrees.delete(sessionId);
602
return;
603
}
605
>
// Skip if the branch is missing — without it we can't safely recreate
606
>
// the worktree on unarchive, so leave the working tree intact.
607
>
const branchPresent = await this._gitService.branchExists(repositoryRoot, branchName).catch(() => false);
608
>
if (!branchPresent) {
609
this._logService.info(`[${this._logLabel}:${sessionId}] Skipping worktree cleanup: branch '${branchName}' is missing`);
610
return;
611
}
613
>
// Commit any uncommitted changes before archiving the session
614
>
const hasUncommittedChanges = await this._gitService.hasUncommittedChanges(worktreePath).catch(() => true);
615
>
if (hasUncommittedChanges) {
616
try {
617
await this._gitService.commitAll(worktreePath, localize('worktreeIsolation.commitMessage', 'Saving uncommitted changes before archiving session'));