Background - use merge-base commit for the left hand side of the diff editor#311026
Merged
Background - use merge-base commit for the left hand side of the diff editor#311026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Copilot CLI chat sessions’ diff construction so the left-hand side (original) of the diff editor uses the merge-base commit (when available), aligning the editor view with how git diffs are computed (e.g., --merge-base).
Changes:
- Compute and persist
mergeBaseCommit(andbaseCommitfor workspace sessions) in repository/session metadata. - Use
mergeBaseCommitas the original ref when creatingChatSessionChangedFileentries for workspace sessions. - Extend worktree/session property types to carry
mergeBaseCommit.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/vscode-node/folderRepositoryManagerImpl.ts | Computes merge-base and stores baseCommit/mergeBaseCommit into RepositoryProperties during repo discovery. |
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts | Uses stored merge-base ref when building workspace changed-file entries. |
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts | Uses merge-base/base commit as the diff original ref for workspace changed-file entries. |
| extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts | Adds merge-base tracking and uses it for diff original ref selection in agent sessions workspaces. |
| extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorkspaceFolderServiceImpl.ts | Computes merge-base commit during workspace diff computation and stores it back to metadata. |
| extensions/copilot/src/extension/chatSessions/common/chatSessionWorktreeService.ts | Adds mergeBaseCommit?: string to worktree properties v2. |
| extensions/copilot/src/extension/chatSessions/common/chatSessionMetadataStore.ts | Adds baseCommit?: string and mergeBaseCommit?: string to RepositoryProperties. |
Copilot's findings
Comments suppressed due to low confidence (4)
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts:782
ILogService.erroris intended for logging exception details by passing theErrorobject as the first argument and an optional stable context string as the second. Interpolating${error}into the message can leak error details/customer data and loses stack traces; pass the error separately and keep the message free of error contents.
} catch (error) {
this.logService.error(`[ChatSessionWorktreeService][_getWorktreeChanges] Error while getting merge base (${worktreeProperties.branchName}, ${worktreeProperties.baseBranchName}) for session ${sessionId}: ${error}`);
}
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorkspaceFolderServiceImpl.ts:254
- The workspace diff is computed via
git diff ... --merge-base <baseBranchName>(i.e. merge-base withHEAD), but this merge-base commit is computed usingrepositoryProperties.branchName. If the user has switched branches, these can diverge. Consider computing the merge base against'HEAD'(orrepository.headBranchName) to match the diff baseline, or only computing it when the stored branch matches the current HEAD branch.
if (repositoryProperties.branchName && repositoryProperties.baseBranchName) {
mergeBaseCommit = await this.gitService.getMergeBase(repository.rootUri, repositoryProperties.branchName, repositoryProperties.baseBranchName);
}
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorkspaceFolderServiceImpl.ts:257
ILogService.errorshould receive the thrown error as the first argument and a stable context message as the second; avoid embedding${error}in the message (it can include stack/message). Pass the error object separately and keep the message to branch/session context only.
} catch (error) {
this.logService.error(`[ChatSessionWorkspaceFolderService][getWorkspaceChanges] Error while getting merge base (${repositoryProperties.branchName}, ${repositoryProperties.baseBranchName}): ${error}`);
}
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts:822
originalFileRefnow prefersworktreeProperties.mergeBaseCommit, but ingetWorktreeChanges()the returnedchanges.map(...)uses the pre-updateworktreePropertiesobject (beforesetWorktreeProperties(..., ...properties)), so the newly computed/storedmergeBaseCommitwon’t be used in the first result. Consider mapping with an updated properties object (e.g.,{ ...worktreeProperties, ...properties }) so the diff LHS uses the merge-base immediately.
if (worktreeProperties.version === 2) {
// Commit | Working tree
originalFileRef = vscode.workspace.isAgentSessionsWorkspace
? worktreeProperties.mergeBaseCommit ?? worktreeProperties.baseCommit
: worktreeProperties.baseCommit;
- Files reviewed: 7/7 changed files
- Comments generated: 4
Contributor
roblourens
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.