瀏覽代碼

Adds compare references command to the palette

main
Eric Amodio 4 年之前
父節點
當前提交
f29bb1adf5
共有 8 個文件被更改,包括 133 次插入119 次删除
  1. +1
    -0
      CHANGELOG.md
  2. +3
    -2
      README.md
  3. +29
    -16
      package.json
  4. +1
    -1
      src/commands.ts
  5. +5
    -2
      src/commands/common.ts
  6. +88
    -0
      src/commands/compareWith.ts
  7. +0
    -92
      src/commands/diffBranchWith.ts
  8. +6
    -6
      src/views/searchAndCompareView.ts

+ 1
- 0
CHANGELOG.md 查看文件

@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added
- Adds a _Compare References..._ command (`gitlens.compareWith`) to compare two selected references
- Adds ability to enter reference ranges (e.g. `main...release/1.0`) to the _Git Command Palette_'s _history_ command
### Fixed

+ 3
- 2
README.md 查看文件

@ -563,8 +563,9 @@ Additionally, these integrations provide commands to copy the url of or open, fi
- Adds a _Switch to Another Branch_ (`gitlens.views.switchToAnotherBranch`) command — to quickly switch the current branch
- Adds a _Compare HEAD with..._ command (`gitlens.diffHeadWith`) to compare the index (HEAD) with the selected reference
- Adds a _Compare Working Tree with..._ command (`gitlens.diffWorkingWith`) to compare the working tree with the selected reference
- Adds a _Compare References..._ command (`gitlens.compareWith`) to compare two selected references
- Adds a _Compare HEAD with..._ command (`gitlens.compareHeadWith`) to compare the index (HEAD) with the selected reference
- Adds a _Compare Working Tree with..._ command (`gitlens.compareWorkingWith`) to compare the working tree with the selected reference
- Adds an _Open Changes (difftool)_ command (`gitlens.externalDiff`) to open the changes of a file or set of files with the configured git difftool
- Adds an _Open All Changes (difftool)_ command (`gitlens.externalDiffAll`) to open all working changes with the configured git difftool

+ 29
- 16
package.json 查看文件

@ -86,10 +86,11 @@
"onCommand:gitlens.showWelcomeView",
"onCommand:gitlens.closeUpdatesView",
"onCommand:gitlens.closeWelcomeView",
"onCommand:gitlens.compareWith",
"onCommand:gitlens.compareHeadWith",
"onCommand:gitlens.compareWorkingWith",
"onCommand:gitlens.diffDirectory",
"onCommand:gitlens.diffDirectoryWithHead",
"onCommand:gitlens.diffHeadWith",
"onCommand:gitlens.diffWorkingWith",
"onCommand:gitlens.diffWithNext",
"onCommand:gitlens.diffWithNextInDiffLeft",
"onCommand:gitlens.diffWithNextInDiffRight",
@ -2622,23 +2623,31 @@
"icon": "$(close)"
},
{
"command": "gitlens.diffDirectory",
"title": "Open Directory Compare (difftool) with...",
"category": "GitLens"
"command": "gitlens.compareWith",
"title": "Compare References...",
"category": "GitLens",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.diffDirectoryWithHead",
"title": "Open Directory Compare (difftool)",
"category": "GitLens"
"command": "gitlens.compareHeadWith",
"title": "Compare HEAD with...",
"category": "GitLens",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.diffHeadWith",
"title": "Compare HEAD with...",
"command": "gitlens.compareWorkingWith",
"title": "Compare Working Tree with...",
"category": "GitLens",
"icon": "$(compare-changes)"
},
{
"command": "gitlens.diffDirectory",
"title": "Open Directory Compare (difftool) with...",
"category": "GitLens"
},
{
"command": "gitlens.diffWorkingWith",
"title": "Compare Working Tree with...",
"command": "gitlens.diffDirectoryWithHead",
"title": "Open Directory Compare (difftool)",
"category": "GitLens"
},
{
@ -4446,19 +4455,23 @@
"when": "false"
},
{
"command": "gitlens.diffDirectory",
"command": "gitlens.compareWith",
"when": "gitlens:enabled"
},
{
"command": "gitlens.diffDirectoryWithHead",
"command": "gitlens.compareHeadWith",
"when": "gitlens:enabled"
},
{
"command": "gitlens.diffHeadWith",
"command": "gitlens.compareWorkingWith",
"when": "gitlens:enabled"
},
{
"command": "gitlens.diffWorkingWith",
"command": "gitlens.diffDirectory",
"when": "gitlens:enabled"
},
{
"command": "gitlens.diffDirectoryWithHead",
"when": "gitlens:enabled"
},
{

+ 1
- 1
src/commands.ts 查看文件

@ -5,9 +5,9 @@ export * from './commands/browseRepoAtRevision';
export * from './commands/closeUnchangedFiles';
export * from './commands/closeView';
export * from './commands/common';
export * from './commands/compareWith';
export * from './commands/copyMessageToClipboard';
export * from './commands/copyShaToClipboard';
export * from './commands/diffBranchWith';
export * from './commands/openDirectoryCompare';
export * from './commands/diffLineWithPrevious';
export * from './commands/diffLineWithWorking';

+ 5
- 2
src/commands/common.ts 查看文件

@ -32,6 +32,9 @@ export enum Commands {
CloseUnchangedFiles = 'gitlens.closeUnchangedFiles',
CloseUpdatesView = 'gitlens.closeUpdatesView',
CloseWelcomeView = 'gitlens.closeWelcomeView',
CompareWith = 'gitlens.compareWith',
CompareHeadWith = 'gitlens.compareHeadWith',
CompareWorkingWith = 'gitlens.compareWorkingWith',
ComputingFileAnnotations = 'gitlens.computingFileAnnotations',
ConnectRemoteProvider = 'gitlens.connectRemoteProvider',
CopyMessageToClipboard = 'gitlens.copyMessageToClipboard',
@ -45,8 +48,6 @@ export enum Commands {
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
DiffDirectory = 'gitlens.diffDirectory',
DiffDirectoryWithHead = 'gitlens.diffDirectoryWithHead',
DiffHeadWith = 'gitlens.diffHeadWith',
DiffWorkingWith = 'gitlens.diffWorkingWith',
DiffWith = 'gitlens.diffWith',
DiffWithNext = 'gitlens.diffWithNext',
DiffWithNextInDiffLeft = 'gitlens.diffWithNextInDiffLeft',
@ -151,6 +152,8 @@ export enum Commands {
ViewsOpenDirectoryDiff = 'gitlens.views.openDirectoryDiff',
ViewsOpenDirectoryDiffWithWorking = 'gitlens.views.openDirectoryDiffWithWorking',
Deprecated_DiffHeadWith = 'gitlens.diffHeadWith',
Deprecated_DiffWorkingWith = 'gitlens.diffWorkingWith',
Deprecated_OpenBranchesInRemote = 'gitlens.openBranchesInRemote',
Deprecated_OpenBranchInRemote = 'gitlens.openBranchInRemote',
Deprecated_OpenCommitInRemote = 'gitlens.openCommitInRemote',

+ 88
- 0
src/commands/compareWith.ts 查看文件

@ -0,0 +1,88 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
} from './common';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
export interface CompareWithCommandArgs {
ref1?: string;
ref2?: string;
}
@command()
export class CompareWithCommand extends ActiveEditorCommand {
constructor() {
super([
Commands.CompareWith,
Commands.CompareHeadWith,
Commands.CompareWorkingWith,
Commands.Deprecated_DiffHeadWith,
Commands.Deprecated_DiffWorkingWith,
]);
}
protected preExecute(context: CommandContext, args?: CompareWithCommandArgs) {
switch (context.command) {
case Commands.CompareWith:
args = { ...args };
break;
case Commands.CompareHeadWith:
case Commands.Deprecated_DiffHeadWith:
args = { ...args };
args.ref1 = 'HEAD';
break;
case Commands.CompareWorkingWith:
case Commands.Deprecated_DiffWorkingWith:
args = { ...args };
args.ref1 = '';
break;
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: CompareWithCommandArgs) {
uri = getCommandUri(uri, editor);
args = { ...args };
try {
let title;
switch (args.ref1) {
case null:
title = 'Compare';
break;
case '':
title = 'Compare Working Tree with';
break;
case 'HEAD':
title = 'Compare HEAD with';
break;
default:
title = `Compare ${args.ref1} with`;
break;
}
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, title);
if (!repoPath) return;
if (args.ref1 != null && args.ref2 != null) {
void (await Container.searchAndCompareView.compare(repoPath, args.ref1, args.ref2));
} else {
Container.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true });
}
} catch (ex) {
Logger.error(ex, 'CompareWithCommmand');
void Messages.showGenericErrorMessage('Unable to open comparison');
}
}
}

+ 0
- 92
src/commands/diffBranchWith.ts 查看文件

@ -1,92 +0,0 @@
'use strict';
import { TextEditor, Uri } from 'vscode';
import {
ActiveEditorCommand,
command,
CommandContext,
Commands,
getCommandUri,
getRepoPathOrActiveOrPrompt,
} from './common';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
export interface DiffBranchWithCommandArgs {
ref1?: string;
ref2?: string;
}
@command()
export class DiffBranchWithCommand extends ActiveEditorCommand {
constructor() {
super([Commands.DiffHeadWith, Commands.DiffWorkingWith]);
}
protected preExecute(context: CommandContext, args?: DiffBranchWithCommandArgs) {
switch (context.command) {
case Commands.DiffHeadWith:
args = { ...args };
args.ref1 = 'HEAD';
break;
case Commands.DiffWorkingWith:
args = { ...args };
args.ref1 = '';
break;
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: DiffBranchWithCommandArgs) {
uri = getCommandUri(uri, editor);
args = { ...args };
if (args.ref1 == null) return;
try {
// let checkmarks;
let title;
switch (args.ref1) {
case '':
// checkmarks = false;
title = 'Compare Working Tree with';
break;
case 'HEAD':
// checkmarks = false;
title = 'Compare HEAD with';
break;
default:
// checkmarks = true;
title = `Compare ${args.ref1} with`;
break;
}
const repoPath = await getRepoPathOrActiveOrPrompt(uri, editor, title);
if (!repoPath) return;
if (!args.ref2) {
const pick = await ReferencePicker.show(repoPath, title, 'Choose a reference to compare with', {
allowEnteringRefs: true,
picked: args.ref1,
// checkmarks: checkmarks,
include:
ReferencesQuickPickIncludes.BranchesAndTags |
ReferencesQuickPickIncludes.HEAD |
ReferencesQuickPickIncludes.WorkingTree,
});
if (pick == null) return;
args.ref2 = pick.ref;
if (args.ref2 == null) return;
}
void (await Container.searchAndCompareView.compare(repoPath, args.ref1, args.ref2));
} catch (ex) {
Logger.error(ex, 'DiffBranchWithCommand');
void Messages.showGenericErrorMessage('Unable to open branch compare');
}
}
}

+ 6
- 6
src/views/searchAndCompareView.ts 查看文件

@ -180,7 +180,7 @@ export class SearchAndCompareViewNode extends ViewNode {
void (await this.view.compare(repoPath, selectedRef.ref, ref));
}
async selectForCompare(repoPath?: string, ref?: string | NamedRef) {
async selectForCompare(repoPath?: string, ref?: string | NamedRef, options?: { prompt?: boolean }) {
if (repoPath == null) {
repoPath = await getRepoPathOrPrompt('Compare');
}
@ -188,7 +188,7 @@ export class SearchAndCompareViewNode extends ViewNode {
this.removeComparePicker(true);
let autoCompare = false;
let prompt = options?.prompt ?? false;
if (ref == null) {
const pick = await ReferencePicker.show(repoPath, 'Compare', 'Choose a reference to compare', {
allowEnteringRefs: true,
@ -210,7 +210,7 @@ export class SearchAndCompareViewNode extends ViewNode {
ref = pick.ref;
autoCompare = true;
prompt = true;
}
this.comparePicker = new ComparePickerNode(this.view, this, {
@ -225,7 +225,7 @@ export class SearchAndCompareViewNode extends ViewNode {
await this.view.reveal(this.comparePicker, { focus: false, select: true });
if (autoCompare) {
if (prompt) {
await this.compareWithSelected();
}
}
@ -359,8 +359,8 @@ export class SearchAndCompareView extends ViewBase
void this.ensureRoot().compareWithSelected(repoPath, ref);
}
selectForCompare(repoPath?: string, ref?: string | NamedRef) {
void this.ensureRoot().selectForCompare(repoPath, ref);
selectForCompare(repoPath?: string, ref?: string | NamedRef, options?: { prompt?: boolean }) {
void this.ensureRoot().selectForCompare(repoPath, ref, options);
}
async search(

Loading…
取消
儲存