diff --git a/extensions/git/package.json b/extensions/git/package.json index 0e6d3d3ebcd..9e6bdb1f56d 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -851,6 +851,11 @@ "description": "%config.ignoreLegacyWarning%", "default": false }, + "git.ignoreMissingGitWarning": { + "type": "boolean", + "description": "%config.ignoreMissingGitWarning%", + "default": false + }, "git.ignoreLimitWarning": { "type": "boolean", "description": "%config.ignoreLimitWarning%", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index fee56d9e05e..4f6d0fe91f5 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -55,6 +55,7 @@ "config.countBadge": "Controls the git badge counter. `all` counts all changes. `tracked` counts only the tracked changes. `off` turns it off.", "config.checkoutType": "Controls what type of branches are listed when running `Checkout to...`. `all` shows all refs, `local` shows only the local branchs, `tags` shows only tags and `remote` shows only remote branches.", "config.ignoreLegacyWarning": "Ignores the legacy Git warning", + "config.ignoreMissingGitWarning": "Ignores the warning when Git is missing", "config.ignoreLimitWarning": "Ignores the warning when there are too many changes in a repository", "config.defaultCloneDirectory": "The default location where to clone a git repository", "config.enableSmartCommit": "Commit all changes when there are no staged changes.", @@ -66,4 +67,4 @@ "colors.untracked": "Color for untracked resources.", "colors.ignored": "Color for ignored resources.", "colors.conflict": "Color for resources with conflicts." -} +} \ No newline at end of file diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index c00d25f9c56..554165f476c 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1404,11 +1404,6 @@ export class CommandCenter { await repository.pushTo(choice, branchName, true); } - @command('git.showOutput') - showOutput(): void { - this.outputChannel.show(); - } - @command('git.ignore') async ignore(...resourceStates: SourceControlResourceState[]): Promise { if (resourceStates.length === 0 || !(resourceStates[0].resourceUri instanceof Uri)) { diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 21475fbd434..c85ab5551c9 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -131,7 +131,7 @@ function findGitWin32(onLookup: (path: string) => void): Promise { } export function findGit(hint: string | undefined, onLookup: (path: string) => void): Promise { - var first = hint ? findSpecificGit(hint, onLookup) : Promise.reject(null); + const first = hint ? findSpecificGit(hint, onLookup) : Promise.reject(null); return first .then(void 0, () => { diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 9a9f9ead688..b9bc3aedcd3 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -7,7 +7,7 @@ import * as nls from 'vscode-nls'; const localize = nls.config(process.env.VSCODE_NLS_CONFIG)(); -import { ExtensionContext, workspace, window, Disposable, commands, Uri } from 'vscode'; +import { ExtensionContext, workspace, window, Disposable, commands, Uri, OutputChannel } from 'vscode'; import { findGit, Git, IGit } from './git'; import { Model } from './model'; import { CommandCenter } from './commands'; @@ -17,14 +17,11 @@ import { Askpass } from './askpass'; import { toDisposable } from './util'; import TelemetryReporter from 'vscode-extension-telemetry'; -async function init(context: ExtensionContext, disposables: Disposable[]): Promise { +async function init(context: ExtensionContext, outputChannel: OutputChannel, disposables: Disposable[]): Promise { const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string }; const telemetryReporter: TelemetryReporter = new TelemetryReporter(name, version, aiKey); disposables.push(telemetryReporter); - const outputChannel = window.createOutputChannel('Git'); - disposables.push(outputChannel); - const config = workspace.getConfiguration('git'); const enabled = config.get('enabled') === true; const pathHint = workspace.getConfiguration('git').get('path'); @@ -61,18 +58,51 @@ async function init(context: ExtensionContext, disposables: Disposable[]): Promi await checkGitVersion(info); } +async function _activate(context: ExtensionContext, disposables: Disposable[]): Promise { + const outputChannel = window.createOutputChannel('Git'); + commands.registerCommand('git.showOutput', () => outputChannel.show()); + disposables.push(outputChannel); + + try { + await init(context, outputChannel, disposables); + } catch (err) { + if (!/Git installation not found/.test(err.message || '')) { + throw err; + } + + console.warn(err.message); + outputChannel.appendLine(err.message); + outputChannel.show(); + + const config = workspace.getConfiguration('git'); + const shouldIgnore = config.get('ignoreMissingGitWarning') === true; + + if (shouldIgnore) { + return; + } + + const download = localize('downloadgit', "Download Git"); + const neverShowAgain = localize('neverShowAgain', "Don't show again"); + const choice = await window.showWarningMessage( + localize('notfound', "Git not found. Install it or configure it using the 'git.path' setting."), + download, + neverShowAgain + ); + + if (choice === download) { + commands.executeCommand('vscode.open', Uri.parse('https://git-scm.com/')); + } else if (choice === neverShowAgain) { + await config.update('ignoreMissingGitWarning', true, true); + } + } +} + export function activate(context: ExtensionContext): any { const disposables: Disposable[] = []; context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose())); - init(context, disposables) - .catch(err => { - if (/Git installation not found/.test(err.message || '')) { - console.warn(localize('notfound', "Git not found. You can configure its location with the `git.path` configuration setting.")); - } else { - console.error(err); - } - }); + _activate(context, disposables) + .catch(err => console.error(err)); } async function checkGitVersion(info: IGit): Promise {