From 0c13050387087b41eeeba3cb650421502d932b93 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 1 Apr 2017 02:48:53 -0400 Subject: [PATCH] Addresses #57 - adds warning if no diff.tool --- src/commands/diffDirectory.ts | 10 +++++++++- src/git/git.ts | 4 ++++ src/gitService.ts | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/commands/diffDirectory.ts b/src/commands/diffDirectory.ts index 9865bda..897d86e 100644 --- a/src/commands/diffDirectory.ts +++ b/src/commands/diffDirectory.ts @@ -1,7 +1,8 @@ 'use strict'; import { Iterables } from '../system'; -import { TextEditor, Uri, window } from 'vscode'; +import { commands, TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand, Commands } from './common'; +import { BuiltInCommands } from '../constants'; import { GitService } from '../gitService'; import { Logger } from '../logger'; import { CommandQuickPickItem, BranchesQuickPick } from '../quickPicks'; @@ -13,6 +14,13 @@ export class DiffDirectoryCommand extends ActiveEditorCommand { } async execute(editor: TextEditor, uri?: Uri, shaOrBranch1?: string, shaOrBranch2?: string): Promise { + const diffTool = await this.git.getConfig('diff.tool'); + if (!diffTool) { + const result = await window.showWarningMessage(`Unable to open directory compare because there is no Git diff tool configured`, 'View Git Docs'); + if (!result) return undefined; + return commands.executeCommand(BuiltInCommands.Open, Uri.parse('https://git-scm.com/docs/git-config#git-config-difftool')); + } + if (!(uri instanceof Uri)) { uri = editor && editor.document && editor.document.uri; } diff --git a/src/git/git.ts b/src/git/git.ts index 6247097..0da908a 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -150,6 +150,10 @@ export class Git { return gitCommand(repoPath, ...params); } + static config_get(key: string, repoPath?: string) { + return gitCommand(repoPath || '', `config`, `--get`, key); + } + static diff_nameStatus(repoPath: string, sha1?: string, sha2?: string) { const params = [`diff`, `--name-status`, `-M`]; if (sha1) { diff --git a/src/gitService.ts b/src/gitService.ts index 0695adb..dae2af0 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -510,6 +510,12 @@ export class GitService extends Disposable { return Git.normalizePath(fileName).toLowerCase(); } + async getConfig(key: string, repoPath?: string): Promise { + Logger.log(`getConfig('${key}', '${repoPath}')`); + + return await Git.config_get(key, repoPath); + } + getGitUriForFile(fileName: string) { const cacheKey = this.getCacheEntryKey(fileName); const entry = this._uriCache.get(cacheKey);