Browse Source

Changes diffWithWorking to use left diff

Changes openRevision to use left diff
main
Eric Amodio 5 years ago
parent
commit
b88eb545bf
5 changed files with 120 additions and 18 deletions
  1. +46
    -4
      package.json
  2. +2
    -0
      src/commands/common.ts
  3. +29
    -3
      src/commands/diffWithWorking.ts
  4. +42
    -10
      src/commands/openRevisionFile.ts
  5. +1
    -1
      src/git/gitUri.ts

+ 46
- 4
package.json View File

@ -2218,6 +2218,15 @@
}
},
{
"command": "gitlens.diffWithWorkingInDiffRight",
"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"
@ -2479,6 +2488,16 @@
"enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git"
},
{
"command": "gitlens.openRevisionFileInDiffRight",
"title": "Open Revision",
"category": "GitLens",
"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 File",
"category": "GitLens",
@ -3519,7 +3538,11 @@
},
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:activeFileStatus =~ /revision/"
"when": "gitlens:activeFileStatus =~ /revision/ && !isInDiffEditor"
},
{
"command": "gitlens.diffWithWorkingInDiffRight",
"when": "gitlens:activeFileStatus =~ /revision/ && isInDiffRightEditor"
},
{
"command": "gitlens.diffLineWithWorking",
@ -3683,7 +3706,11 @@
},
{
"command": "gitlens.openRevisionFile",
"when": "gitlens:activeFileStatus =~ /revision/"
"when": "gitlens:activeFileStatus =~ /revision/ && isInDiffLeftEditor"
},
{
"command": "gitlens.openRevisionFileInDiffRight",
"when": "gitlens:activeFileStatus =~ /revision/ && isInDiffRightEditor"
},
{
"command": "gitlens.openWorkingFile",
@ -4242,12 +4269,27 @@
"editor/title": [
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && !isInDiffEditor",
"group": "navigation@-99"
},
{
"command": "gitlens.diffWithWorking",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffLeftEditor",
"group": "navigation@-99"
},
{
"command": "gitlens.diffWithWorkingInDiffRight",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffRightEditor",
"group": "navigation@-99"
},
{
"command": "gitlens.openRevisionFile",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffEditor",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffLeftEditor",
"group": "navigation@-98"
},
{
"command": "gitlens.openRevisionFileInDiffRight",
"when": "gitlens:activeFileStatus =~ /revision/ && resourceScheme =~ /^(?!(file|git)$).*$/ && isInDiffRightEditor",
"group": "navigation@-98"
},
{

+ 2
- 0
src/commands/common.ts View File

@ -49,6 +49,7 @@ export enum Commands {
DiffLineWithPrevious = 'gitlens.diffLineWithPrevious',
DiffWithRevision = 'gitlens.diffWithRevision',
DiffWithWorking = 'gitlens.diffWithWorking',
DiffWithWorkingInDiffRight = 'gitlens.diffWithWorkingInDiffRight',
DiffLineWithWorking = 'gitlens.diffLineWithWorking',
ExploreRepoAtRevision = 'gitlens.exploreRepoAtRevision',
ExternalDiff = 'gitlens.externalDiff',
@ -66,6 +67,7 @@ export enum Commands {
OpenInRemote = 'gitlens.openInRemote',
OpenRepoInRemote = 'gitlens.openRepoInRemote',
OpenRevisionFile = 'gitlens.openRevisionFile',
OpenRevisionFileInDiffRight = 'gitlens.openRevisionFileInDiffRight',
OpenWorkingFile = 'gitlens.openWorkingFile',
PullRepositories = 'gitlens.pullRepositories',
PushRepositories = 'gitlens.pushRepositories',

+ 29
- 3
src/commands/diffWithWorking.ts View File

@ -2,10 +2,13 @@
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { Container } from '../container';
import { GitService, GitUri } from '../git/gitService';
import { ActiveEditorCommand, command, Commands, getCommandUri } from './common';
import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common';
import { DiffWithCommandArgs } from './diffWith';
import { Messages } from '../messages';
import { Logger } from '../logger';
export interface DiffWithWorkingCommandArgs {
inDiffRightEditor?: boolean;
line?: number;
showOptions?: TextDocumentShowOptions;
}
@ -13,20 +16,43 @@ export interface DiffWithWorkingCommandArgs {
@command()
export class DiffWithWorkingCommand extends ActiveEditorCommand {
constructor() {
super(Commands.DiffWithWorking);
super([Commands.DiffWithWorking, Commands.DiffWithWorkingInDiffRight]);
}
protected preExecute(context: CommandContext, args?: DiffWithWorkingCommandArgs) {
if (context.command === Commands.DiffWithWorkingInDiffRight) {
args = { ...args };
args.inDiffRightEditor = true;
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: DiffWithWorkingCommandArgs): Promise<any> {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
let gitUri = await GitUri.fromUri(uri);
args = { ...args };
if (args.line === undefined) {
args.line = editor == null ? 0 : editor.selection.active.line;
}
if (args.inDiffRightEditor) {
try {
const diffUris = await Container.git.getPreviousDiffUris(gitUri.repoPath!, gitUri, gitUri.sha, 0);
gitUri = diffUris?.previous ?? gitUri;
} catch (ex) {
Logger.error(
ex,
'DiffWithWorkingCommand',
`getPreviousDiffUris(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`
);
return Messages.showGenericErrorMessage('Unable to open compare');
}
}
// if (args.commit === undefined || args.commit.isUncommitted) {
// If the sha is missing, just let the user know the file matches
if (gitUri.sha === undefined) return window.showInformationMessage('File matches the working tree');

+ 42
- 10
src/commands/openRevisionFile.ts View File

@ -5,10 +5,12 @@ import { Container } from '../container';
import { GitUri } from '../git/gitService';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ActiveEditorCommand, command, Commands, findOrOpenEditor, getCommandUri } from './common';
import { ActiveEditorCommand, command, CommandContext, Commands, findOrOpenEditor, getCommandUri } from './common';
export interface OpenRevisionFileCommandArgs {
uri?: Uri;
inDiffRightEditor?: boolean;
line?: number;
showOptions?: TextDocumentShowOptions;
annotationType?: FileAnnotationType;
@ -17,10 +19,19 @@ export interface OpenRevisionFileCommandArgs {
@command()
export class OpenRevisionFileCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenRevisionFile);
super([Commands.OpenRevisionFile, Commands.OpenRevisionFileInDiffRight]);
}
async execute(editor: TextEditor, uri?: Uri, args?: OpenRevisionFileCommandArgs) {
protected preExecute(context: CommandContext, args?: OpenRevisionFileCommandArgs) {
if (context.command === Commands.OpenRevisionFileInDiffRight) {
args = { ...args };
args.inDiffRightEditor = true;
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: OpenRevisionFileCommandArgs) {
args = { ...args };
if (args.line === undefined) {
args.line = editor == null ? 0 : editor.selection.active.line;
@ -34,14 +45,35 @@ export class OpenRevisionFileCommand extends ActiveEditorCommand {
uri = args.uri;
}
args.uri = await GitUri.fromUri(uri);
if (GitUri.is(args.uri) && args.uri.sha) {
const commit = await Container.git.getCommit(args.uri.repoPath!, args.uri.sha);
const gitUri = await GitUri.fromUri(uri);
if (gitUri?.sha) {
if (args.inDiffRightEditor) {
try {
const diffUris = await Container.git.getPreviousDiffUris(
gitUri.repoPath!,
gitUri,
gitUri.sha,
0
);
args.uri = GitUri.toRevisionUri(diffUris?.previous ?? gitUri);
} catch (ex) {
Logger.error(
ex,
'OpenRevisionFileCommand',
`getPreviousDiffUris(${gitUri?.repoPath}, ${gitUri.fsPath}, ${gitUri?.sha})`
);
return Messages.showGenericErrorMessage('Unable to open revision');
}
} else {
const commit = await Container.git.getCommit(gitUri.repoPath!, gitUri.sha);
args.uri =
commit !== undefined && commit.status === 'D'
? GitUri.toRevisionUri(commit.previousSha!, commit.previousUri.fsPath, commit.repoPath)
: GitUri.toRevisionUri(args.uri);
args.uri =
commit !== undefined && commit.status === 'D'
? GitUri.toRevisionUri(commit.previousSha!, commit.previousUri.fsPath, commit.repoPath)
: GitUri.toRevisionUri(gitUri);
}
} else {
args.uri = GitUri.toRevisionUri(gitUri);
}
if (args.line !== undefined && args.line !== 0) {

+ 1
- 1
src/git/gitUri.ts View File

@ -259,7 +259,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
@debug({
exit: uri => `returned ${Logger.toLoggable(uri)}`
})
static async fromUri(uri: Uri) {
static async fromUri(uri: Uri): Promise<GitUri> {
if (GitUri.is(uri)) return uri;
if (!Container.git.isTrackable(uri)) return new GitUri(uri);

Loading…
Cancel
Save