diff --git a/CHANGELOG.md b/CHANGELOG.md index 9232b31..3358279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fixes [#436](https://github.com/eamodio/vscode-gitlens/issues/436) - Copy to clipboard not working - Fixes [#442](https://github.com/eamodio/vscode-gitlens/issues/442) - GitLens File History fails if name (or path) starts with - - Fixes [#440](https://github.com/eamodio/vscode-gitlens/issues/436) - Searching for commits with an empty query yields to no results anymore +- Fixes issue where the *Compare File with Previous Revision* command wouldn't work properly when the file had been renamed in some cases - Fixes issue where changed files count was wrong when the branch was behind the upstream - Fixes issue where the *GitLens File History* explorer wasn't being updated automatically for working changes - Fixes issue where the *Compare File with * Revision* commands in the editor toolbar would show and hide too often because of insignificant focus changes diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 70d0950..ae890a9 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -58,16 +58,39 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { sha = sha + '^'; } - const log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { + args.commit = undefined; + + let log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, ref: sha, renames: true }); - if (log === undefined) { - return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); + + if (log !== undefined) { + args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); } + else { + // Only kick out if we aren't looking for the previous sha -- since renames won't return a log above + if (sha === undefined || !sha.endsWith('^')) { + return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); + } + + // Check for renames + log = await Container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { + maxCount: 4, + ref: sha.substring(0, sha.length - 1), + renames: true + }); - args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); + if (log === undefined) { + return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); + } + + args.commit = Iterables.next(Iterables.skip(log.commits.values(), 2)); + if (args.commit === undefined) { + args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); + } + } // If the sha is missing (i.e. working tree), check the file status // If file is uncommitted, then treat it as a DiffWithWorking diff --git a/src/system/iterable.ts b/src/system/iterable.ts index 43d1bb4..06c0c99 100644 --- a/src/system/iterable.ts +++ b/src/system/iterable.ts @@ -133,10 +133,7 @@ export namespace Iterables { return source.next().value; } - export function* skip( - source: Iterable | IterableIterator, - count: number - ): Iterable | IterableIterator { + export function* skip(source: Iterable | IterableIterator, count: number): IterableIterator { let i = 0; for (const item of source) { if (i >= count) yield item;