Procházet zdrojové kódy

Fixes external directory compare

Adds advanced.externalDiffTool setting
Adds advanced.externalDirectoryDiffTool setting
main
Eric Amodio před 3 roky
rodič
revize
046bb45911
10 změnil soubory, kde provedl 118 přidání a 102 odebrání
  1. +3
    -0
      CHANGELOG.md
  2. +2
    -0
      README.md
  3. +18
    -0
      package.json
  4. +2
    -2
      src/commands/common.ts
  5. +10
    -9
      src/commands/externalDiff.ts
  6. +15
    -53
      src/commands/gitCommands.actions.ts
  7. +5
    -20
      src/commands/openDirectoryCompare.ts
  8. +2
    -0
      src/config.ts
  9. +60
    -17
      src/git/gitService.ts
  10. +1
    -1
      src/quickpicks/commitQuickPickItems.ts

+ 3
- 0
CHANGELOG.md Zobrazit soubor

@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds a new _Copy Current Branch Name_ (`gitlens.copyCurrentBranch`) command to copy the current branch name to the clipboard — closes [#1306](https://github.com/eamodio/vscode-gitlens/issues/1306) — thanks to [PR #1307](https://github.com/eamodio/vscode-gitlens/pull/1307) by Ken Hom ([@kh0m](https://github.com/kh0m))
- Adds a `gitlens.advanced.abbreviateShaOnCopy` setting to specify to whether to copy full or abbreviated commit SHAs to the clipboard. Abbreviates to the length of `gitlens.advanced.abbreviatedShaLength` — closes [#1062](https://github.com/eamodio/vscode-gitlens/issues/1062) — thanks to [PR #1316](https://github.com/eamodio/vscode-gitlens/pull/1316) by Brendon Smith ([@br3ndonland](https://github.com/br3ndonland))
- Adds a _Switch to Text_ button on the _Interactive Rebase Editor_ to open the text rebase todo file — note that closing either document will start the rebase
- Adds a `gitlens.advanced.externalDiffTool` setting to specify an optional external diff tool to use when comparing files. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool).
- Adds a `gitlens.advanced.externalDirectoryDiffTool` setting to specify an optional external diff tool to use when comparing directories. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool).
### Changed
@ -37,6 +39,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Fixes [#1309](https://github.com/eamodio/vscode-gitlens/issues/1309) - "Fetch" not working on remote branches
- Fixes an issue where many views wouldn't refresh properly when going from no items to some items
- Fixes an issue where _Publish Branch_ was incorrectly showing up on remote branches
- Fixes an issue where the _Open Directory Compare \*_ commands failed to work
## [11.1.3] - 2021-01-05

+ 2
- 0
README.md Zobrazit soubor

@ -962,6 +962,8 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
| `gitlens.advanced.blame.delayAfterEdit` | Specifies the time (in milliseconds) to wait before re-blaming an unsaved document after an edit. Use 0 to specify an infinite wait |
| `gitlens.advanced.blame.sizeThresholdAfterEdit` | Specifies the maximum document size (in lines) allowed to be re-blamed after an edit while still unsaved. Use 0 to specify no maximum |
| `gitlens.advanced.caching.enabled` | Specifies whether git output will be cached — changing the default is not recommended |
| `gitlens.advanced.externalDiffTool` | Specifies an optional external diff tool to use when comparing files. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool). |
| `gitlens.advanced.externalDirectoryDiffTool` | Specifies an optional external diff tool to use when comparing directories. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool). |
| `gitlens.advanced.fileHistoryFollowsRenames` | Specifies whether file histories will follow renames -- will affect how merge commits are shown in histories |
| `gitlens.advanced.fileHistoryShowAllBranches` | Specifies whether file histories will show commits from all branches |
| `gitlens.advanced.maxListItems` | Specifies the maximum number of items to show in a list. Use 0 to specify no maximum |

+ 18
- 0
package.json Zobrazit soubor

@ -2381,6 +2381,24 @@
"markdownDescription": "Specifies whether git output will be cached — changing the default is not recommended",
"scope": "window"
},
"gitlens.advanced.externalDiffTool": {
"type": [
"string",
"null"
],
"default": null,
"markdownDescription": "Specifies an optional external diff tool to use when comparing files. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool).",
"scope": "window"
},
"gitlens.advanced.externalDirectoryDiffTool": {
"type": [
"string",
"null"
],
"default": null,
"markdownDescription": "Specifies an optional external diff tool to use when comparing directories. Must be a configured [Git difftool](https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool).",
"scope": "window"
},
"gitlens.advanced.fileHistoryFollowsRenames": {
"type": "boolean",
"default": false,

+ 2
- 2
src/commands/common.ts Zobrazit soubor

@ -19,7 +19,7 @@ import {
import { Action, ActionContext } from '../api/gitlens';
import { BuiltInCommands, DocumentSchemes, ImageMimetypes } from '../constants';
import { Container } from '../container';
import { GitBranch, GitCommit, GitContributor, GitFile, GitRemote, GitTag, Repository } from '../git/git';
import { GitBranch, GitCommit, GitContributor, GitFile, GitReference, GitRemote, GitTag, Repository } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { CommandQuickPickItem, RepositoryPicker } from '../quickpicks';
@ -355,7 +355,7 @@ export function isCommandContextViewNodeHasFileRefs(
export function isCommandContextViewNodeHasRef(
context: CommandContext,
): context is CommandViewNodeContext & { node: ViewNode & { ref: string } } {
): context is CommandViewNodeContext & { node: ViewNode & { ref: GitReference } } {
return context.type === 'viewItem' && context.node instanceof ViewRefNode;
}

+ 10
- 9
src/commands/externalDiff.ts Zobrazit soubor

@ -182,17 +182,18 @@ export class ExternalDiffCommand extends Command {
if (!repoPath) return;
}
const tool = await Container.git.getDiffTool(repoPath);
if (tool == null) {
const tool = Container.config.advanced.externalDiffTool || (await Container.git.getDiffTool(repoPath));
if (!tool) {
const viewDocs = 'View Git Docs';
const result = await window.showWarningMessage(
'Unable to open changes in diff tool. No Git diff tool is configured',
'View Git Docs',
);
if (!result) return;
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
'Unable to open changes because no Git diff tool is configured',
viewDocs,
);
if (result === viewDocs) {
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
}
return;
}

+ 15
- 53
src/commands/gitCommands.actions.ts Zobrazit soubor

@ -27,8 +27,8 @@ import {
Repository,
} from '../git/git';
import { GitUri } from '../git/gitUri';
import { RepositoryPicker } from '../quickpicks';
import { ResetGitCommandArgs } from './git/reset';
import { RepositoryPicker } from '../quickpicks';
export async function executeGitCommand(args: GitCommandsCommandArgs): Promise<void> {
void (await executeCommand<GitCommandsCommandArgs>(Commands.GitCommands, args));
@ -375,12 +375,12 @@ export namespace GitActions {
}));
}
export async function openChangesWithDiffTool(
export function openChangesWithDiffTool(
file: string | GitFile,
commit: GitLogCommit,
tool?: string,
): Promise<void>;
export async function openChangesWithDiffTool(
export function openChangesWithDiffTool(
file: GitFile,
ref: { repoPath: string; ref: string },
tool?: string,
@ -399,24 +399,7 @@ export namespace GitActions {
file = f;
}
if (!tool) {
tool = await Container.git.getDiffTool(commitOrRef.repoPath);
if (tool == null) {
const result = await window.showWarningMessage(
'Unable to open changes in diff tool. No Git diff tool is configured',
'View Git Docs',
);
if (!result) return;
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
return;
}
}
void Container.git.openDiffTool(
return Container.git.openDiffTool(
commitOrRef.repoPath,
GitUri.fromFile(file, file.repoPath ?? commitOrRef.repoPath),
{
@ -473,45 +456,24 @@ export namespace GitActions {
}
export async function openDirectoryCompare(
repoPath: string,
ref: string,
ref2: string | undefined,
tool?: string,
): Promise<void> {
return Container.git.openDirectoryCompare(repoPath, ref, ref2, tool);
}
export async function openDirectoryCompareWithPrevious(
ref: { repoPath: string; ref: string } | GitLogCommit,
): Promise<void> {
try {
void (await Container.git.openDirectoryCompare(ref.repoPath, ref.ref, `${ref.ref}^`));
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg === 'No diff tool found') {
const result = await window.showWarningMessage(
'Unable to open directory compare because there is no Git diff tool configured',
'View Git Docs',
);
if (!result) return;
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
}
}
return openDirectoryCompare(ref.repoPath, ref.ref, `${ref.ref}^`);
}
export async function openDirectoryCompareWithWorking(
ref: { repoPath: string; ref: string } | GitLogCommit,
): Promise<void> {
try {
void (await Container.git.openDirectoryCompare(ref.repoPath, ref.ref, undefined));
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg === 'No diff tool found') {
const result = await window.showWarningMessage(
'Unable to open directory compare because there is no Git diff tool configured',
'View Git Docs',
);
if (!result) return;
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
}
}
return openDirectoryCompare(ref.repoPath, ref.ref, undefined);
}
export async function openFile(uri: Uri, options?: TextDocumentShowOptions): Promise<void>;

+ 5
- 20
src/commands/openDirectoryCompare.ts Zobrazit soubor

@ -1,5 +1,6 @@
'use strict';
import { env, TextEditor, Uri, window } from 'vscode';
import { TextEditor, Uri } from 'vscode';
import { GitActions } from '../commands';
import {
ActiveEditorCommand,
command,
@ -9,7 +10,6 @@ import {
getRepoPathOrActiveOrPrompt,
isCommandContextViewNodeHasRef,
} from './common';
import { Container } from '../container';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { ReferencePicker } from '../quickpicks';
@ -49,7 +49,7 @@ export class OpenDirectoryCompareCommand extends ActiveEditorCommand {
case Commands.ViewsOpenDirectoryDiffWithWorking:
if (isCommandContextViewNodeHasRef(context)) {
args = { ...args };
args.ref1 = context.node.ref;
args.ref1 = context.node.ref.ref;
args.ref2 = undefined;
}
break;
@ -82,24 +82,9 @@ export class OpenDirectoryCompareCommand extends ActiveEditorCommand {
if (args.ref1 == null) return;
}
void Container.git.openDirectoryCompare(repoPath, args.ref1, args.ref2);
void GitActions.Commit.openDirectoryCompare(repoPath, args.ref1, args.ref2);
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg === 'No diff tool found') {
const result = await window.showWarningMessage(
'Unable to open directory compare because there is no Git diff tool configured',
'View Git Docs',
);
if (!result) return;
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
return;
}
Logger.error(ex, 'DiffDirectoryCommand');
Logger.error(ex, 'OpenDirectoryCompareCommand');
void Messages.showGenericErrorMessage('Unable to open directory compare');
}
}

+ 2
- 0
src/config.ts Zobrazit soubor

@ -287,6 +287,8 @@ export interface AdvancedConfig {
caching: {
enabled: boolean;
};
externalDiffTool: string | null;
externalDirectoryDiffTool: string | null;
fileHistoryFollowsRenames: boolean;
fileHistoryShowAllBranches: boolean;
maxListItems: number;

+ 60
- 17
src/git/gitService.ts Zobrazit soubor

@ -4,6 +4,7 @@ import * as paths from 'path';
import {
ConfigurationChangeEvent,
Disposable,
env,
Event,
EventEmitter,
Extension,
@ -3818,32 +3819,74 @@ export class GitService implements Disposable {
repoPath: string,
uri: Uri,
options: { ref1?: string; ref2?: string; staged?: boolean; tool?: string } = {},
) {
if (!options.tool) {
const cc = Logger.getCorrelationContext();
): Promise<void> {
try {
if (!options.tool) {
const cc = Logger.getCorrelationContext();
options.tool = await this.getDiffTool(repoPath);
if (options.tool == null) throw new Error('No diff tool found');
options.tool = Container.config.advanced.externalDiffTool || (await this.getDiffTool(repoPath));
if (options.tool == null) throw new Error('No diff tool found');
Logger.log(cc, `Using tool=${options.tool}`);
}
Logger.log(cc, `Using tool=${options.tool}`);
}
const { tool, ...opts } = options;
await Git.difftool(repoPath, uri.fsPath, tool, opts);
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg === 'No diff tool found' || /Unknown .+? tool/.test(msg)) {
const viewDocs = 'View Git Docs';
const result = await window.showWarningMessage(
'Unable to open changes because the specified diff tool cannot be found or no Git diff tool is configured',
viewDocs,
);
if (result === viewDocs) {
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
}
return;
}
const { tool, ...opts } = options;
return Git.difftool(repoPath, uri.fsPath, tool, opts);
Logger.error(ex, 'openDiffTool');
void Messages.showGenericErrorMessage('Unable to open compare');
}
}
@log()
async openDirectoryCompare(repoPath: string, ref1: string, ref2?: string, tool?: string) {
if (!tool) {
const cc = Logger.getCorrelationContext();
async openDirectoryCompare(repoPath: string, ref1: string, ref2?: string, tool?: string): Promise<void> {
try {
if (!tool) {
const cc = Logger.getCorrelationContext();
tool = await this.getDiffTool(repoPath);
if (tool == null) throw new Error('No diff tool found');
tool = Container.config.advanced.externalDirectoryDiffTool || (await this.getDiffTool(repoPath));
if (tool == null) throw new Error('No diff tool found');
Logger.log(cc, `Using tool=${tool}`);
}
Logger.log(cc, `Using tool=${tool}`);
}
return Git.difftool__dir_diff(repoPath, tool, ref1, ref2);
await Git.difftool__dir_diff(repoPath, tool, ref1, ref2);
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (msg === 'No diff tool found' || /Unknown .+? tool/.test(msg)) {
const viewDocs = 'View Git Docs';
const result = await window.showWarningMessage(
'Unable to open directory compare because the specified diff tool cannot be found or no Git diff tool is configured',
viewDocs,
);
if (result === viewDocs) {
void env.openExternal(
Uri.parse('https://git-scm.com/docs/git-config#Documentation/git-config.txt-difftool'),
);
}
return;
}
Logger.error(ex, 'openDirectoryCompare');
void Messages.showGenericErrorMessage('Unable to open directory compare');
}
}
async resolveReference(

+ 1
- 1
src/quickpicks/commitQuickPickItems.ts Zobrazit soubor

@ -214,7 +214,7 @@ export class CommitOpenDirectoryCompareCommandQuickPickItem extends CommandQuick
}
execute(): Promise<void> {
return GitActions.Commit.openDirectoryCompare(this.commit);
return GitActions.Commit.openDirectoryCompareWithPrevious(this.commit);
}
}

Načítá se…
Zrušit
Uložit