From 05f70cd3a8e12e8db8e1be4eeecb8b4bb80f83fe Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Fri, 20 Feb 2026 13:47:06 +0100 Subject: [PATCH] Background - fix changes paths in the working set (#3893) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Background - fix changes paths in the working set * Pull request feedback --------- Co-authored-by: João Moreno --- .../chatSessionWorktreeServiceImpl.ts | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts b/extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts index 5c46c22572d..7c1a92154d3 100644 --- a/extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts +++ b/extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts @@ -328,19 +328,28 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi return []; } - const changes = diff.map(change => ({ - filePath: change.uri.fsPath, - originalFilePath: change.status !== 1 /* INDEX_ADDED */ - ? change.originalUri?.fsPath - : undefined, - modifiedFilePath: change.status !== 6 /* DELETED */ - ? change.uri.fsPath - : undefined, - statistics: { - additions: change.insertions, - deletions: change.deletions - } - } satisfies ChatSessionWorktreeFile)); + const changes = diff.map(change => { + // Since the diff was computed using the main repository, the file paths in the diff are relative to the + // main repository. We need to convert them to absolute paths by joining them with the repository path. + const worktreeFilePath = path.join(worktreeProperties.worktreePath, path.relative(worktreeProperties.repositoryPath, change.uri.fsPath)); + const worktreeOriginalFilePath = change.originalUri + ? path.join(worktreeProperties.worktreePath, path.relative(worktreeProperties.repositoryPath, change.originalUri.fsPath)) + : undefined; + + return { + filePath: worktreeFilePath, + originalFilePath: change.status !== 1 /* INDEX_ADDED */ + ? worktreeOriginalFilePath + : undefined, + modifiedFilePath: change.status !== 6 /* DELETED */ + ? worktreeFilePath + : undefined, + statistics: { + additions: change.insertions, + deletions: change.deletions + } + } satisfies ChatSessionWorktreeFile; + }); this.setWorktreeProperties(sessionId, { ...worktreeProperties, changes @@ -349,7 +358,6 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi return changes; } - getSessionIdForWorktree(folder: vscode.Uri): string | undefined { for (const [sessionId, value] of this._sessionWorktrees.entries()) { if (typeof value === 'string') {