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') {