Skip to content

Commit 1e6f456

Browse files
committed
Use the correct path
1 parent 3ffb197 commit 1e6f456

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/common/uri.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ export namespace DataUri {
323323
}
324324
}
325325

326+
/**
327+
* @param fileName The repo relative path to the file
328+
*/
329+
export function reviewPath(fileName: string, commitSha: string) {
330+
return vscode.Uri.parse(pathUtils.posix.join(`commit~${commitSha.substr(0, 8)}`, fileName));
331+
}
332+
326333
export function toReviewUri(
327334
uri: vscode.Uri,
328335
filePath: string | undefined,

src/github/pullRequestModel.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Logger from '../common/logger';
1717
import { Remote } from '../common/remote';
1818
import { ITelemetry } from '../common/telemetry';
1919
import { ClosedEvent, EventType, ReviewEvent } from '../common/timelineEvent';
20-
import { resolvePath, Schemes, toPRUri, toReviewUri } from '../common/uri';
20+
import { resolvePath, reviewPath, Schemes, toPRUri, toReviewUri } from '../common/uri';
2121
import { formatError, isDescendant } from '../common/utils';
2222
import { InMemFileChangeModel, RemoteFileChangeModel } from '../view/fileChangeModel';
2323
import { OctokitCommon } from './common';
@@ -1217,28 +1217,22 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12171217
// Create URI pairs for the multi diff editor using review scheme
12181218
const args: [vscode.Uri, vscode.Uri | undefined, vscode.Uri | undefined][] = [];
12191219
for (const change of changes) {
1220-
const uri = vscode.Uri.file(path.resolve(repository.rootUri.fsPath, change.uri.fsPath));
1221-
const fileName = change.uri.fsPath;
1220+
const rightRelativePath = path.relative(repository.rootUri.fsPath, change.uri.fsPath);
1221+
const rightPath = reviewPath(rightRelativePath, commitSha);
1222+
let rightUri = toReviewUri(rightPath, rightRelativePath, undefined, commitSha, false, { base: false }, repository.rootUri);
1223+
1224+
const leftRelativePath = path.relative(repository.rootUri.fsPath, change.originalUri.fsPath);
1225+
const leftPath = reviewPath(leftRelativePath, parentSha);
1226+
let leftUri = toReviewUri(leftPath, (change.status === GitChangeType.RENAME) ? path.relative(repository.rootUri.fsPath, change.originalUri.fsPath) : leftRelativePath, undefined, parentSha, false, { base: true }, repository.rootUri);
12221227

12231228
if (change.status === GitChangeType.ADD) {
12241229
// For added files, show against empty
1225-
const headUri = toReviewUri(uri, fileName, undefined, commitSha, false, { base: false }, repository.rootUri);
1226-
args.push([headUri, undefined, headUri]);
1230+
args.push([rightUri, undefined, rightUri]);
12271231
} else if (change.status === GitChangeType.DELETE) {
12281232
// For deleted files, show old version against empty
1229-
const baseUri = toReviewUri(uri, fileName, undefined, parentSha, false, { base: true }, repository.rootUri);
1230-
args.push([uri, baseUri, undefined]);
1231-
} else if (change.status === GitChangeType.RENAME) {
1232-
// For renamed files, show old name against new name
1233-
const baseFileName = change.originalUri.fsPath;
1234-
const baseUri = toReviewUri(uri, baseFileName, undefined, parentSha, false, { base: true }, repository.rootUri);
1235-
const headUri = toReviewUri(uri, fileName, undefined, commitSha, false, { base: false }, repository.rootUri);
1236-
args.push([headUri, baseUri, headUri]);
1233+
args.push([rightPath, leftUri, undefined]);
12371234
} else {
1238-
// For modified files, show before and after
1239-
const baseUri = toReviewUri(uri, fileName, undefined, parentSha, false, { base: true }, repository.rootUri);
1240-
const headUri = toReviewUri(uri, fileName, undefined, commitSha, false, { base: false }, repository.rootUri);
1241-
args.push([headUri, baseUri, headUri]);
1235+
args.push([rightUri, leftUri, rightUri]);
12421236
}
12431237
}
12441238

src/view/treeNodes/commitNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as path from 'path';
76
import * as vscode from 'vscode';
87
import { getGitChangeType } from '../../common/diffHunk';
98
import { FILE_LIST_LAYOUT, PR_SETTINGS_NAMESPACE } from '../../common/settingKeys';
10-
import { DataUri, toReviewUri } from '../../common/uri';
9+
import { DataUri, reviewPath, toReviewUri } from '../../common/uri';
1110
import { dateFromNow } from '../../common/utils';
1211
import { OctokitCommon } from '../../github/common';
1312
import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
@@ -58,7 +57,7 @@ export class CommitNode extends TreeNode implements vscode.TreeItem {
5857

5958
const fileChangeNodes = fileChanges.map(change => {
6059
const fileName = change.filename!;
61-
const uri = vscode.Uri.parse(path.posix.join(`commit~${this.commit.sha.substr(0, 8)}`, fileName));
60+
const uri = reviewPath(fileName, this.commit.sha);
6261
const changeModel = new GitFileChangeModel(
6362
this.pullRequestManager,
6463
this.pullRequest,

0 commit comments

Comments
 (0)