From f0c5df885f2ede4aad6cbda8526a13948a265cee Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 28 Sep 2018 01:45:37 -0400 Subject: [PATCH] Fixes issue with diff files added in index/working tree --- src/commands/diffWith.ts | 3 ++- src/git/git.ts | 2 ++ src/git/gitService.ts | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands/diffWith.ts b/src/commands/diffWith.ts index e402889..46639a1 100644 --- a/src/commands/diffWith.ts +++ b/src/commands/diffWith.ts @@ -108,7 +108,8 @@ export class DiffWithCommand extends ActiveEditorCommand { if (args.lhs.sha !== GitService.deletedOrMissingSha) { lhsSha = args.lhs.sha; } - if (args.rhs.sha !== GitService.deletedOrMissingSha) { + + if (args.rhs.sha && args.rhs.sha !== GitService.deletedOrMissingSha) { // Ensure that the file still exists in this commit const status = await Container.git.getFileStatusForCommit( args.repoPath, diff --git a/src/git/git.ts b/src/git/git.ts index 74204e3..6c70c19 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -511,6 +511,8 @@ export class Git { } static async cat_file_validate(repoPath: string, fileName: string, ref: string) { + if (Git.isUncommitted(ref)) return ref; + try { await git( { cwd: repoPath, exceptionHandler: throwExceptionHandler }, diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 8fa1c89..260ab06 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1850,14 +1850,17 @@ export class GitService implements Disposable { } async resolveReference(repoPath: string, ref: string, uri?: Uri) { - if (Git.isSha(ref) || !Git.isShaLike(ref) || ref.endsWith('^3')) return ref; - Logger.log(`resolveReference('${repoPath}', '${ref}', '${uri && uri.toString(true)}')`); - if (uri == null) return (await Git.revparse(repoPath, ref)) || ref; + const resolved = Git.isSha(ref) || !Git.isShaLike(ref) || ref.endsWith('^3'); + if (uri == null) return resolved ? ref : (await Git.revparse(repoPath, ref)) || ref; const fileName = Strings.normalizePath(paths.relative(repoPath, uri.fsPath)); - const resolvedRef = await Git.log_resolve(repoPath, fileName, ref); + + let resolvedRef; + if (!resolved) { + resolvedRef = await Git.log_resolve(repoPath, fileName, ref); + } const ensuredRef = await Git.cat_file_validate(repoPath, fileName, resolvedRef || ref); if (ensuredRef === undefined) return ref;