From 50ba3e1446060b5a58b8e440c9cab624a72219df Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 9 Jun 2017 10:45:04 -0400 Subject: [PATCH] Fixes #84 - diff w/ previous should only compare w/ working tree if file is uncommitted --- src/commands/diffWithNext.ts | 2 +- src/commands/diffWithPrevious.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index 45e1e94..5903862 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -37,7 +37,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand { const sha = args.commit === undefined ? gitUri.sha : args.commit.sha; - const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha ? undefined : 2, args.range!); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha !== undefined ? undefined : 2, args.range!); if (log === undefined) return window.showWarningMessage(`Unable to open compare. File is probably not under source control`); args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index d209c0a..3e7205d 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -34,13 +34,13 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { try { const sha = args.commit === undefined ? gitUri.sha : args.commit.sha; - const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha ? undefined : 2, args.range!); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha !== undefined ? undefined : 2, args.range!); if (log === undefined) return window.showWarningMessage(`Unable to open compare. File is probably not under source control`); args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); - // If the sha is missing, treat it as a DiffWithWorking - if (gitUri.sha === undefined) return commands.executeCommand(Commands.DiffWithWorking, uri, { commit: args.commit, showOptions: args.showOptions } as DiffWithWorkingCommandArgs); + // If the sha is missing and the file is uncommitted, then treat it as a DiffWithWorking + if (gitUri.sha === undefined && await this.git.isFileUncommitted(gitUri)) return commands.executeCommand(Commands.DiffWithWorking, uri, { commit: args.commit, showOptions: args.showOptions } as DiffWithWorkingCommandArgs); } catch (ex) { Logger.error(ex, 'DiffWithPreviousCommand', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`);