diff --git a/src/commands/diffWith.ts b/src/commands/diffWith.ts index 54e57ff..9ad4c5f 100644 --- a/src/commands/diffWith.ts +++ b/src/commands/diffWith.ts @@ -113,8 +113,8 @@ export class DiffWithCommand extends ActiveEditorCommand { } const [lhs, rhs] = await Promise.all([ - Container.git.getVersionedFile(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha), - Container.git.getVersionedFile(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha) + Container.git.getVersionedUri(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha), + Container.git.getVersionedUri(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha) ]); let rhsSuffix = GitService.shortenSha(rhsSha, { uncommitted: 'working tree' }) || ''; diff --git a/src/git/gitService.ts b/src/git/gitService.ts index fd3f9e0..68533ff 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1677,7 +1677,7 @@ export class GitService implements Disposable { return GitTreeParser.parse(data) || []; } - async getVersionedFile( + async getVersionedUri( repoPath: string | undefined, fileName: string, ref: string | undefined @@ -1692,6 +1692,16 @@ export class GitService implements Disposable { return undefined; } + if (Git.isStagedUncommitted(ref)) { + const path = paths.resolve(repoPath || '', fileName); + return Uri.parse( + `git:${path}?${JSON.stringify({ + path: path, + ref: '~' + })}` + ); + } + return GitUri.toRevisionUri(ref, fileName, repoPath!); }