From aee22ed470dc52fad3cc5ff017223e4d73d7f370 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 7 Sep 2019 04:08:39 -0400 Subject: [PATCH] Addresses #723 - keeps icon more stable Fixes issue with wrong diff line with previous Fixes issues with previous/next when on right/left side of diff editor --- CHANGELOG.md | 5 +- package.json | 172 +++++++++++++++++++++------------------ src/commands/common.ts | 5 +- src/commands/diffWithNext.ts | 26 +++--- src/commands/diffWithPrevious.ts | 24 ++---- src/commands/diffWithWorking.ts | 23 +----- src/git/gitService.ts | 61 ++++++++------ 7 files changed, 155 insertions(+), 161 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f22f5d..37547ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,9 +65,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fixes [#821](https://github.com/eamodio/vscode-gitlens/issues/821) - Wrong comparison order in the Compare view when using Compare [HEAD|Working Tree] With comands - Fixes [#794](https://github.com/eamodio/vscode-gitlens/issues/794) - Can't get back to settings page easily - Fixes [#738](https://github.com/eamodio/vscode-gitlens/issues/738) - Disable showWhatsNewAfterUpgrades notification -- Fixes typo of "workbench.colorCustomization" in README — thanks to [PR #823](https://github.com/eamodio/vscode-gitlens/pull/823) by Kwok ([@mankwok](https://github.com/mankwok)) +- Fixes [#723](https://github.com/eamodio/vscode-gitlens/issues/723) (partially) - Top right tool loading/placement enhancement +- Fixes issue where the _Open Line Changes with Previous Revision_ command would open the correct comparison in the diff editor +- Fixes some issues with the _Open Changes with [Previous|Next] Revision_ commands when in the right or left side of the diff editor - Fixes an issue with branch sorting when the current branch was tree'd - Fixes an issue with the _Explore Repository from Revision_ command in the latest VS Code Insiders +- Fixes typo of "workbench.colorCustomization" in README — thanks to [PR #823](https://github.com/eamodio/vscode-gitlens/pull/823) by Kwok ([@mankwok](https://github.com/mankwok)) ## [9.9.3] - 2019-08-06 diff --git a/package.json b/package.json index 52182c7..7c75441 100644 --- a/package.json +++ b/package.json @@ -2054,16 +2054,18 @@ "icon": { "dark": "images/dark/icon-next-commit.svg", "light": "images/light/icon-next-commit.svg" - } + }, + "enablement": "gitlens:activeFileStatus =~ /revision/" }, { - "command": "gitlens.diffWithNextInDiff", + "command": "gitlens.diffWithNextInDiffLeft", "title": "Open Changes with Next Revision", "category": "GitLens", "icon": { "dark": "images/dark/icon-next-commit.svg", "light": "images/light/icon-next-commit.svg" - } + }, + "enablement": "gitlens:activeFileStatus =~ /revision/" }, { "command": "gitlens.diffWithPrevious", @@ -2075,7 +2077,7 @@ } }, { - "command": "gitlens.diffWithPreviousInDiff", + "command": "gitlens.diffWithPreviousInDiffRight", "title": "Open Changes with Previous Revision", "category": "GitLens", "icon": { @@ -2107,15 +2109,6 @@ } }, { - "command": "gitlens.diffWithWorkingInDiff", - "title": "Open Changes with Working File", - "category": "GitLens", - "icon": { - "dark": "images/dark/icon-compare-ref-working.svg", - "light": "images/light/icon-compare-ref-working.svg" - } - }, - { "command": "gitlens.diffLineWithWorking", "title": "Open Line Changes with Working File", "category": "GitLens" @@ -2241,7 +2234,8 @@ "icon": { "dark": "images/dark/icon-commit.svg", "light": "images/light/icon-commit.svg" - } + }, + "enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git" }, { "command": "gitlens.showQuickFileHistory", @@ -2367,11 +2361,12 @@ "icon": { "dark": "images/dark/icon-open-revision.svg", "light": "images/light/icon-open-revision.svg" - } + }, + "enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git" }, { "command": "gitlens.openWorkingFile", - "title": "Open Working File", + "title": "Open File", "category": "GitLens", "icon": { "dark": "images/dark/icon-open-working-file.svg", @@ -2445,7 +2440,8 @@ "icon": { "dark": "images/dark/icon-open-folder.svg", "light": "images/light/icon-open-folder.svg" - } + }, + "enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git" }, { "command": "gitlens.views.exploreRepoAtRevision", @@ -3291,19 +3287,27 @@ }, { "command": "gitlens.diffWithNext", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "gitlens:activeFileStatus =~ /revision/ && !isInDiffEditor" }, { - "command": "gitlens.diffWithNextInDiff", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "command": "gitlens.diffWithNext", + "when": "gitlens:activeFileStatus =~ /revision/ && isInDiffRightEditor" + }, + { + "command": "gitlens.diffWithNextInDiffLeft", + "when": "gitlens:activeFileStatus =~ /revision/ && isInDiffLeftEditor" }, { "command": "gitlens.diffWithPrevious", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "when": "gitlens:activeFileStatus =~ /tracked/ && !isInDiffEditor" }, { - "command": "gitlens.diffWithPreviousInDiff", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "command": "gitlens.diffWithPrevious", + "when": "gitlens:activeFileStatus =~ /tracked/ && isInDiffLeftEditor" + }, + { + "command": "gitlens.diffWithPreviousInDiffRight", + "when": "gitlens:activeFileStatus =~ /tracked/ && isInDiffRightEditor" }, { "command": "gitlens.diffLineWithPrevious", @@ -3315,11 +3319,7 @@ }, { "command": "gitlens.diffWithWorking", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /revision/" - }, - { - "command": "gitlens.diffWithWorkingInDiff", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "gitlens:activeFileStatus =~ /revision/" }, { "command": "gitlens.diffLineWithWorking", @@ -4013,65 +4013,66 @@ ], "editor/title": [ { - "command": "gitlens.diffWithWorking", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git", - "group": "navigation@0" + "command": "gitlens.exploreRepoAtRevision", + "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/", + "group": "navigation@-100" }, { - "command": "gitlens.diffWithWorkingInDiff", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git", - "group": "navigation@0" + "command": "gitlens.diffWithWorking", + "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/", + "group": "navigation@-99" }, { - "command": "gitlens.openWorkingFile", - "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git", - "group": "navigation@1" + "command": "gitlens.openRevisionFile", + "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffEditor", + "group": "navigation@-98" }, { "command": "gitlens.openWorkingFile", - "when": "!gitlens:activeFileStatus =~ /revision/ && resourceScheme != file && resourceScheme != git && isInDiffEditor", - "group": "navigation@1" + "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/", + "group": "navigation@-97" }, { "command": "gitlens.openWorkingFile", "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme == git && !isInDiffEditor", - "group": "navigation@1" + "group": "navigation@-97" }, { - "command": "gitlens.openRevisionFile", - "when": "gitlens:activeFileStatus =~ /revision/ && isInDiffEditor", - "group": "navigation@2" - }, - { - "command": "gitlens.exploreRepoAtRevision", - "when": "gitlens:activeFileStatus =~ /revision/", - "group": "navigation@3" + "command": "gitlens.diffWithPrevious", + "alt": "gitlens.diffWithRevision", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && !isInDiffEditor", + "group": "navigation@97" }, { "command": "gitlens.diffWithPrevious", "alt": "gitlens.diffWithRevision", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && isInDiffLeftEditor", "group": "navigation@97" }, { - "command": "gitlens.diffWithPreviousInDiff", + "command": "gitlens.diffWithPreviousInDiffRight", "alt": "gitlens.diffWithRevision", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && isInDiffRightEditor", "group": "navigation@97" }, { "command": "gitlens.showQuickRevisionDetails", - "when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git && config.gitlens.menus.editorGroup.compare", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare", "group": "navigation@98" }, { "command": "gitlens.diffWithNext", - "when": "!isInDiffEditor && gitlens:activeFileStatus =~ /revision/ && config.gitlens.menus.editorGroup.compare", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && !isInDiffEditor", + "group": "navigation@99" + }, + { + "command": "gitlens.diffWithNext", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && isInDiffRightEditor", "group": "navigation@99" }, { - "command": "gitlens.diffWithNextInDiff", - "when": "isInDiffEditor && gitlens:activeFileStatus =~ /revision/ && config.gitlens.menus.editorGroup.compare", + "command": "gitlens.diffWithNextInDiffLeft", + "when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editorGroup.compare && isInDiffLeftEditor", "group": "navigation@99" }, { @@ -5315,22 +5316,32 @@ { "command": "gitlens.diffWithNext", "key": "alt+.", - "when": "config.gitlens.keymap == alternate && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && !isInDiffEditor" }, { - "command": "gitlens.diffWithNextInDiff", + "command": "gitlens.diffWithNext", "key": "alt+.", - "when": "config.gitlens.keymap == alternate && isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && isInDiffRightEditor" + }, + { + "command": "gitlens.diffWithNextInDiffLeft", + "key": "alt+.", + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && isInDiffLeftEditor" + }, + { + "command": "gitlens.diffWithPrevious", + "key": "alt+,", + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && !isInDiffEditor" }, { "command": "gitlens.diffWithPrevious", "key": "alt+,", - "when": "config.gitlens.keymap == alternate && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && isInDiffLeftEditor" }, { - "command": "gitlens.diffWithPreviousInDiff", + "command": "gitlens.diffWithPreviousInDiffRight", "key": "alt+,", - "when": "config.gitlens.keymap == alternate && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && isInDiffRightEditor" }, { "command": "gitlens.diffLineWithPrevious", @@ -5340,12 +5351,7 @@ { "command": "gitlens.diffWithWorking", "key": "shift+alt+.", - "when": "config.gitlens.keymap == alternate && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /revision/" - }, - { - "command": "gitlens.diffWithWorkingInDiff", - "key": "shift+alt+.", - "when": "config.gitlens.keymap == alternate && isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /revision/" }, { "command": "gitlens.diffLineWithWorking", @@ -5404,25 +5410,37 @@ "command": "gitlens.diffWithNext", "key": "ctrl+shift+g .", "mac": "cmd+alt+g .", - "when": "config.gitlens.keymap == chorded && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && !isInDiffEditor" + }, + { + "command": "gitlens.diffWithNext", + "key": "ctrl+shift+g .", + "mac": "cmd+alt+g .", + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && isInDiffRightEditor" }, { - "command": "gitlens.diffWithNextInDiff", + "command": "gitlens.diffWithNextInDiffLeft", "key": "ctrl+shift+g .", "mac": "cmd+alt+g .", - "when": "config.gitlens.keymap == chorded && isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /revision/ && isInDiffLeftEditor" }, { "command": "gitlens.diffWithPrevious", "key": "ctrl+shift+g ,", "mac": "cmd+alt+g ,", - "when": "config.gitlens.keymap == chorded && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && !isInDiffEditor" }, { - "command": "gitlens.diffWithPreviousInDiff", + "command": "gitlens.diffWithPrevious", + "key": "ctrl+shift+g ,", + "mac": "cmd+alt+g ,", + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && isInDiffLeftEditor" + }, + { + "command": "gitlens.diffWithPreviousInDiffRight", "key": "ctrl+shift+g ,", "mac": "cmd+alt+g ,", - "when": "config.gitlens.keymap == chorded && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/" + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/ && isInDiffRightEditor" }, { "command": "gitlens.diffLineWithPrevious", @@ -5434,13 +5452,7 @@ "command": "gitlens.diffWithWorking", "key": "ctrl+shift+g shift+.", "mac": "cmd+alt+g shift+.", - "when": "config.gitlens.keymap == chorded && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /revision/" - }, - { - "command": "gitlens.diffWithWorkingInDiff", - "key": "ctrl+shift+g shift+.", - "mac": "cmd+alt+g shift+.", - "when": "config.gitlens.keymap == chorded && isInDiffEditor && gitlens:activeFileStatus =~ /revision/" + "when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /revision/" }, { "command": "gitlens.diffLineWithWorking", diff --git a/src/commands/common.ts b/src/commands/common.ts index 9c3f482..f1995a4 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -43,13 +43,12 @@ export enum Commands { DiffWithBranch = 'gitlens.diffWithBranch', DiffWithRef = 'gitlens.diffWithRef', DiffWithNext = 'gitlens.diffWithNext', - DiffWithNextInDiff = 'gitlens.diffWithNextInDiff', + DiffWithNextInDiffLeft = 'gitlens.diffWithNextInDiffLeft', DiffWithPrevious = 'gitlens.diffWithPrevious', - DiffWithPreviousInDiff = 'gitlens.diffWithPreviousInDiff', + DiffWithPreviousInDiffRight = 'gitlens.diffWithPreviousInDiffRight', DiffLineWithPrevious = 'gitlens.diffLineWithPrevious', DiffWithRevision = 'gitlens.diffWithRevision', DiffWithWorking = 'gitlens.diffWithWorking', - DiffWithWorkingInDiff = 'gitlens.diffWithWorkingInDiff', DiffLineWithWorking = 'gitlens.diffLineWithWorking', ExploreRepoAtRevision = 'gitlens.exploreRepoAtRevision', ExternalDiff = 'gitlens.externalDiff', diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index fe3d9d2..a6ff2a0 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -6,12 +6,12 @@ import { Logger } from '../logger'; import { Messages } from '../messages'; import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common'; import { DiffWithCommandArgs } from './diffWith'; -import { UriComparer } from '../comparers'; export interface DiffWithNextCommandArgs { commit?: GitLogCommit; range?: Range; + inDiffLeftEditor?: boolean; line?: number; showOptions?: TextDocumentShowOptions; } @@ -19,22 +19,12 @@ export interface DiffWithNextCommandArgs { @command() export class DiffWithNextCommand extends ActiveEditorCommand { constructor() { - super([Commands.DiffWithNext, Commands.DiffWithNextInDiff]); + super([Commands.DiffWithNext, Commands.DiffWithNextInDiffLeft]); } protected preExecute(context: CommandContext, args: DiffWithNextCommandArgs = {}) { - if ( - context.command === Commands.DiffWithNextInDiff - // || (context.editor !== undefined && context.editor.viewColumn === undefined) - ) { - // HACK: If in a diff, try to determine if we are on the right or left side - // If there is a context uri and it doesn't match the editor uri, assume we are on the left - // If on the left, use the editor uri and pretend we aren't in a diff - if (context.uri !== undefined && context.editor !== undefined && context.editor.document !== undefined) { - if (!UriComparer.equals(context.uri, context.editor.document.uri, { exact: true })) { - return this.execute(context.editor, context.editor.document.uri, args); - } - } + if (context.command === Commands.DiffWithNextInDiffLeft) { + args.inDiffLeftEditor = true; } return this.execute(context.editor, context.uri, args); @@ -51,7 +41,13 @@ export class DiffWithNextCommand extends ActiveEditorCommand { const gitUri = args.commit !== undefined ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri); try { - const diffUris = await Container.git.getNextDiffUris(gitUri.repoPath!, gitUri, gitUri.sha); + const diffUris = await Container.git.getNextDiffUris( + gitUri.repoPath!, + gitUri, + gitUri.sha, + // If we are in the left-side of the diff editor, we need to skip forward 1 more revision + args.inDiffLeftEditor ? 1 : 0 + ); if (diffUris === undefined || diffUris.next === undefined) return undefined; diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 610cd94..dd4511f 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -6,12 +6,11 @@ import { Logger } from '../logger'; import { Messages } from '../messages'; import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri, openEditor } from './common'; import { DiffWithCommandArgs } from './diffWith'; -import { UriComparer } from '../comparers'; export interface DiffWithPreviousCommandArgs { commit?: GitCommit; - inDiffEditor?: boolean; + inDiffRightEditor?: boolean; line?: number; showOptions?: TextDocumentShowOptions; } @@ -19,23 +18,12 @@ export interface DiffWithPreviousCommandArgs { @command() export class DiffWithPreviousCommand extends ActiveEditorCommand { constructor() { - super([Commands.DiffWithPrevious, Commands.DiffWithPreviousInDiff]); + super([Commands.DiffWithPrevious, Commands.DiffWithPreviousInDiffRight]); } protected preExecute(context: CommandContext, args: DiffWithPreviousCommandArgs = {}) { - if ( - context.command === Commands.DiffWithPreviousInDiff - // || (context.editor !== undefined && context.editor.viewColumn === undefined) - ) { - // HACK: If in a diff, try to determine if we are on the right or left side - // If there is a context uri and it doesn't match the editor uri, assume we are on the left - // If on the left, use the editor uri and pretend we aren't in a diff - if (context.uri !== undefined && context.editor !== undefined && context.editor.document !== undefined) { - if (!UriComparer.equals(context.uri, context.editor.document.uri, { exact: true })) { - return this.execute(context.editor, context.editor.document.uri, args); - } - } - args.inDiffEditor = true; + if (context.command === Commands.DiffWithPreviousInDiffRight) { + args.inDiffRightEditor = true; } return this.execute(context.editor, context.uri, args); @@ -79,8 +67,8 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { gitUri.repoPath!, gitUri, gitUri.sha, - // If we are in a diff editor, assume we are on the right side, and need to skip back 1 more revisions - args.inDiffEditor ? 1 : 0 + // If we are in the right-side of the diff editor, we need to skip back 1 more revision + args.inDiffRightEditor ? 1 : 0 ); if (diffUris === undefined || diffUris.previous === undefined) { diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index be66118..35bbbe7 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -4,9 +4,8 @@ import { Container } from '../container'; import { GitCommit, GitService, GitUri } from '../git/gitService'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common'; +import { ActiveEditorCommand, command, Commands, getCommandUri } from './common'; import { DiffWithCommandArgs } from './diffWith'; -import { UriComparer } from '../comparers'; export interface DiffWithWorkingCommandArgs { commit?: GitCommit; @@ -18,25 +17,7 @@ export interface DiffWithWorkingCommandArgs { @command() export class DiffWithWorkingCommand extends ActiveEditorCommand { constructor() { - super([Commands.DiffWithWorking, Commands.DiffWithWorkingInDiff]); - } - - protected preExecute(context: CommandContext, args: DiffWithWorkingCommandArgs = {}) { - if ( - context.command === Commands.DiffWithWorkingInDiff - // || (context.editor !== undefined && context.editor.viewColumn === undefined) - ) { - // HACK: If in a diff, try to determine if we are on the right or left side - // If there is a context uri and it doesn't match the editor uri, assume we are on the left - // If on the left, use the editor uri and pretend we aren't in a diff - if (context.uri !== undefined && context.editor !== undefined && context.editor.document !== undefined) { - if (!UriComparer.equals(context.uri, context.editor.document.uri, { exact: true })) { - return this.execute(context.editor, context.editor.document.uri, args); - } - } - } - - return this.execute(context.editor, context.uri, args); + super(Commands.DiffWithWorking); } async execute(editor?: TextEditor, uri?: Uri, args: DiffWithWorkingCommandArgs = {}): Promise { diff --git a/src/git/gitService.ts b/src/git/gitService.ts index a659c1e..d33d5d1 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1744,7 +1744,8 @@ export class GitService implements Disposable { async getNextDiffUris( repoPath: string, uri: Uri, - ref: string | undefined + ref: string | undefined, + skip: number = 0 ): Promise<{ current: GitUri; next: GitUri | undefined; deleted?: boolean } | undefined> { // If we have no ref (or staged ref) there is no next commit if (ref === undefined || ref.length === 0) return undefined; @@ -1758,7 +1759,7 @@ export class GitService implements Disposable { }; } - const next = await this.getNextUri(repoPath, uri, ref); + const next = await this.getNextUri(repoPath, uri, ref, skip); if (next === undefined) { const status = await this.getStatusForFile(repoPath, fileName); if (status !== undefined) { @@ -1778,7 +1779,10 @@ export class GitService implements Disposable { } return { - current: GitUri.fromFile(fileName, repoPath, ref), + current: + skip === 0 + ? GitUri.fromFile(fileName, repoPath, ref) + : (await this.getNextUri(repoPath, uri, ref, skip - 1))!, next: next }; } @@ -1924,6 +1928,8 @@ export class GitService implements Disposable { let fileName = GitUri.relativeTo(uri, repoPath); + let previous; + // If we are at the working tree (i.e. no ref), we need to dig deeper to figure out where to go if (ref === undefined || ref.length === 0) { // First, check the blame on the current line to see if there are any working/staged changes @@ -1984,29 +1990,38 @@ export class GitService implements Disposable { fileName = blameLine.commit.fileName || blameLine.commit.originalFileName || fileName; uri = GitUri.resolveToUri(fileName, repoPath); editorLine = blameLine.line.originalLine - 1; + + if (skip === 0 && blameLine.commit.previousSha) { + previous = GitUri.fromFile(fileName, repoPath, blameLine.commit.previousSha); + } + } + } else { + if (GitService.isUncommittedStaged(ref)) { + const current = + skip === 0 + ? GitUri.fromFile(fileName, repoPath, ref) + : (await this.getPreviousUri(repoPath, uri, undefined, skip - 1, editorLine))!; + if (current.sha === GitService.deletedOrMissingSha) return undefined; + + return { + current: current, + previous: await this.getPreviousUri(repoPath, uri, undefined, skip, editorLine) + }; } - const current = - skip === 0 - ? GitUri.fromFile(fileName, repoPath, ref) - : (await this.getPreviousUri(repoPath, uri, ref, skip - 1, editorLine))!; - if (current.sha === GitService.deletedOrMissingSha) return undefined; + const gitUri = new GitUri(uri, { repoPath: repoPath, sha: ref }); + const blameLine = await this.getBlameForLine(gitUri, editorLine); + if (blameLine === undefined) return undefined; - return { - current: current, - previous: await this.getPreviousUri(repoPath, uri, ref, skip, editorLine) - }; - } else if (GitService.isUncommittedStaged(ref)) { - const current = - skip === 0 - ? GitUri.fromFile(fileName, repoPath, ref) - : (await this.getPreviousUri(repoPath, uri, undefined, skip - 1, editorLine))!; - if (current.sha === GitService.deletedOrMissingSha) return undefined; + // Diff with line ref with previous + ref = blameLine.commit.sha; + fileName = blameLine.commit.fileName || blameLine.commit.originalFileName || fileName; + uri = GitUri.resolveToUri(fileName, repoPath); + editorLine = blameLine.line.originalLine - 1; - return { - current: current, - previous: await this.getPreviousUri(repoPath, uri, undefined, skip, editorLine) - }; + if (skip === 0 && blameLine.commit.previousSha) { + previous = GitUri.fromFile(fileName, repoPath, blameLine.commit.previousSha); + } } const current = @@ -2017,7 +2032,7 @@ export class GitService implements Disposable { return { current: current, - previous: await this.getPreviousUri(repoPath, uri, ref, skip, editorLine) + previous: previous || (await this.getPreviousUri(repoPath, uri, ref, skip, editorLine)) }; }