Skip to content

Commit 707e061

Browse files
authored
Git - use commit id for the left-hand editor (microsoft#194302)
* Git - use commit id for the left-hand editor * Remove console.log
1 parent d2302f4 commit 707e061

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

extensions/git/src/historyProvider.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,19 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
102102
}
103103

104104
async provideHistoryItemChanges(historyItemId: string): Promise<SourceControlHistoryItemChange[]> {
105-
const [ref1, ref2] = historyItemId.includes('..')
106-
? historyItemId.split('..')
107-
: [`${historyItemId}^`, historyItemId];
105+
// The "All Changes" history item uses a special id
106+
// which is a commit range instead of a single commit id
107+
let [originalRef, modifiedRef] = historyItemId.includes('..')
108+
? historyItemId.split('..') : [undefined, historyItemId];
109+
110+
if (!originalRef) {
111+
const commit = await this.repository.getCommit(modifiedRef);
112+
originalRef = commit.parents.length > 0 ? commit.parents[0] : `${modifiedRef}^`;
113+
}
108114

109115
const historyItemChangesUri: Uri[] = [];
110116
const historyItemChanges: SourceControlHistoryItemChange[] = [];
111-
const changes = await this.repository.diffBetween(ref1, ref2);
117+
const changes = await this.repository.diffBetween(originalRef, modifiedRef);
112118

113119
for (const change of changes) {
114120
const historyItemUri = change.uri.with({
@@ -118,8 +124,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
118124
// History item change
119125
historyItemChanges.push({
120126
uri: historyItemUri,
121-
originalUri: toGitUri(change.originalUri, ref1),
122-
modifiedUri: toGitUri(change.originalUri, ref2),
127+
originalUri: toGitUri(change.originalUri, originalRef),
128+
modifiedUri: toGitUri(change.originalUri, modifiedRef),
123129
renameUri: change.renameUri,
124130
});
125131

0 commit comments

Comments
 (0)