Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git - use commit id for the left-hand editor #194302

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,19 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
}

async provideHistoryItemChanges(historyItemId: string): Promise<SourceControlHistoryItemChange[]> {
const [ref1, ref2] = historyItemId.includes('..')
? historyItemId.split('..')
: [`${historyItemId}^`, historyItemId];
// The "All Changes" history item uses a special id
// which is a commit range instead of a single commit id
let [originalRef, modifiedRef] = historyItemId.includes('..')
? historyItemId.split('..') : [undefined, historyItemId];

if (!originalRef) {
const commit = await this.repository.getCommit(modifiedRef);
originalRef = commit.parents.length > 0 ? commit.parents[0] : `${modifiedRef}^`;
}

const historyItemChangesUri: Uri[] = [];
const historyItemChanges: SourceControlHistoryItemChange[] = [];
const changes = await this.repository.diffBetween(ref1, ref2);
const changes = await this.repository.diffBetween(originalRef, modifiedRef);

for (const change of changes) {
const historyItemUri = change.uri.with({
Expand All @@ -118,8 +124,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
// History item change
historyItemChanges.push({
uri: historyItemUri,
originalUri: toGitUri(change.originalUri, ref1),
modifiedUri: toGitUri(change.originalUri, ref2),
originalUri: toGitUri(change.originalUri, originalRef),
modifiedUri: toGitUri(change.originalUri, modifiedRef),
renameUri: change.renameUri,
});

Expand Down