Skip to content

Commit 95f590f

Browse files
committed
Closes #195 - use diff.guitool
1 parent 68d7282 commit 95f590f

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Changed
9+
- Changes to use `diff.guitool` first if available, before falling back to `diff.tool` -- closes [#195](https://github.com/eamodio/vscode-gitlens/issues/195)
10+
11+
### Fixed
12+
- Fixes issue where failed git commands would get stuck in the pending queue causing future similar commands to also fail
13+
714
## [6.0.0] - 2017-11-08
815

916
### Added

src/commands/diffDirectory.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
3232
}
3333

3434
async execute(editor?: TextEditor, uri?: Uri, args: DiffDirectoryCommandCommandArgs = {}): Promise<any> {
35-
const diffTool = await this.git.getConfig('diff.tool');
36-
if (!diffTool) {
37-
const result = await window.showWarningMessage(`Unable to open directory compare because there is no Git diff tool configured`, 'View Git Docs');
38-
if (!result) return undefined;
39-
40-
return commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://git-scm.com/docs/git-config#git-config-difftool'));
41-
}
42-
4335
uri = getCommandUri(uri, editor);
4436

4537
try {
@@ -66,6 +58,14 @@ export class DiffDirectoryCommand extends ActiveEditorCommand {
6658
return undefined;
6759
}
6860
catch (ex) {
61+
const msg = ex && ex.toString();
62+
if (msg === 'No diff tool found') {
63+
const result = await window.showWarningMessage(`Unable to open directory compare because there is no Git diff tool configured`, 'View Git Docs');
64+
if (!result) return undefined;
65+
66+
return commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://git-scm.com/docs/git-config#git-config-difftool'));
67+
}
68+
6969
Logger.error(ex, 'DiffDirectoryCommand');
7070
return window.showErrorMessage(`Unable to open directory compare. See output channel for more details`);
7171
}

src/commands/externalDiff.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ export class ExternalDiffCommand extends Command {
8686

8787
async execute(args: ExternalDiffCommandArgs = {}) {
8888
try {
89-
const diffTool = await this.git.getConfig('diff.tool');
90-
if (!diffTool) {
89+
const repoPath = await this.git.getRepoPath(undefined);
90+
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
91+
92+
const tool = await this.git.getDiffTool(repoPath);
93+
if (tool === undefined) {
9194
const result = await window.showWarningMessage(`Unable to open file compare because there is no Git diff tool configured`, 'View Git Docs');
9295
if (!result) return undefined;
9396

9497
return commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://git-scm.com/docs/git-config#git-config-difftool'));
9598
}
9699

97-
const repoPath = await this.git.getRepoPath(undefined);
98-
if (!repoPath) return Messages.showNoRepositoryWarningMessage(`Unable to open changed files`);
99-
100100
if (args.files === undefined) {
101101
const status = await this.git.getStatusForRepo(repoPath);
102102
if (status === undefined) return window.showWarningMessage(`Unable to open changed files`);
@@ -115,7 +115,7 @@ export class ExternalDiffCommand extends Command {
115115
}
116116

117117
for (const file of args.files) {
118-
this.git.openDiffTool(repoPath, file.uri, file.staged);
118+
this.git.openDiffTool(repoPath, file.uri, file.staged, tool);
119119
}
120120

121121
return undefined;

src/git/git.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class Git {
244244
return data.trim();
245245
}
246246
catch {
247-
return '';
247+
return undefined;
248248
}
249249
}
250250

@@ -283,17 +283,17 @@ export class Git {
283283
return gitCommand({ cwd: repoPath }, ...params);
284284
}
285285

286-
static difftool_dirDiff(repoPath: string, sha1: string, sha2?: string) {
287-
const params = [`difftool`, `--dir-diff`, sha1];
286+
static difftool_dirDiff(repoPath: string, tool: string, sha1: string, sha2?: string) {
287+
const params = [`difftool`, `--dir-diff`, `--tool=${tool}`, sha1];
288288
if (sha2) {
289289
params.push(sha2);
290290
}
291291

292292
return gitCommand({ cwd: repoPath }, ...params);
293293
}
294294

295-
static difftool_fileDiff(repoPath: string, fileName: string, staged: boolean) {
296-
const params = [`difftool`, `--no-prompt`];
295+
static difftool_fileDiff(repoPath: string, fileName: string, tool: string, staged: boolean) {
296+
const params = [`difftool`, `--no-prompt`, `--tool=${tool}`];
297297
if (staged) {
298298
params.push('--staged');
299299
}

src/gitService.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export class GitService extends Disposable {
576576
return GitDiffParser.parseShortStat(data);
577577
}
578578

579-
async getConfig(key: string, repoPath?: string): Promise<string> {
579+
async getConfig(key: string, repoPath?: string): Promise<string | undefined> {
580580
Logger.log(`getConfig('${key}', '${repoPath}')`);
581581

582582
return await Git.config_get(key, repoPath);
@@ -1086,16 +1086,30 @@ export class GitService extends Disposable {
10861086
return tracked;
10871087
}
10881088

1089-
openDiffTool(repoPath: string, uri: Uri, staged: boolean) {
1090-
Logger.log(`openDiffTool('${repoPath}', '${uri.fsPath}', ${staged})`);
1089+
async getDiffTool(repoPath?: string) {
1090+
return await Git.config_get('diff.guitool', repoPath) || await Git.config_get('diff.tool', repoPath);
1091+
}
1092+
1093+
async openDiffTool(repoPath: string, uri: Uri, staged: boolean, tool?: string) {
1094+
if (!tool) {
1095+
tool = await this.getDiffTool(repoPath);
1096+
if (tool === undefined) throw new Error('No diff tool found');
1097+
}
10911098

1092-
return Git.difftool_fileDiff(repoPath, uri.fsPath, staged);
1099+
Logger.log(`openDiffTool('${repoPath}', '${uri.fsPath}', ${staged}, '${tool}')`);
1100+
1101+
return Git.difftool_fileDiff(repoPath, uri.fsPath, tool, staged);
10931102
}
10941103

1095-
openDirectoryDiff(repoPath: string, sha1: string, sha2?: string) {
1096-
Logger.log(`openDirectoryDiff('${repoPath}', '${sha1}', '${sha2}')`);
1104+
async openDirectoryDiff(repoPath: string, sha1: string, sha2?: string, tool?: string) {
1105+
if (!tool) {
1106+
tool = await this.getDiffTool(repoPath);
1107+
if (tool === undefined) throw new Error('No diff tool found');
1108+
}
1109+
1110+
Logger.log(`openDirectoryDiff('${repoPath}', '${sha1}', '${sha2}', '${tool}')`);
10971111

1098-
return Git.difftool_dirDiff(repoPath, sha1, sha2);
1112+
return Git.difftool_dirDiff(repoPath, tool, sha1, sha2);
10991113
}
11001114

11011115
stopWatchingFileSystem() {

0 commit comments

Comments
 (0)