From 95e932c1bb1a1c4725b9b8ea18d1a51bb3d2e688 Mon Sep 17 00:00:00 2001 From: WhizSid Date: Tue, 3 Dec 2019 00:48:16 +0530 Subject: [PATCH 1/3] Multi git executable path --- extensions/git/package.json | 3 ++- extensions/git/src/git.ts | 25 +++++++++++++++++++++++-- extensions/git/src/main.ts | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index d801ec64f97a8..b23603ee5d6de 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -1257,7 +1257,8 @@ "git.path": { "type": [ "string", - "null" + "null", + "array" ], "markdownDescription": "%config.path%", "default": null, diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index af92f83c1a674..b1ab91777a182 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -124,8 +124,29 @@ function findGitWin32(onLookup: (path: string) => void): Promise { .then(undefined, () => findGitWin32InPath(onLookup)); } -export function findGit(hint: string | undefined, onLookup: (path: string) => void): Promise { - const first = hint ? findSpecificGit(hint, onLookup) : Promise.reject(null); +export function findGit(hints: string | string[] | undefined, onLookup: (path: string) => void): Promise { + let first: Promise; + + if (typeof hints === 'object') { + if (hints.length > 0) { + + first = findSpecificGit(hints[0], onLookup); + + let currentHintIndex = 1; + + while (currentHintIndex < hints.length) { + + first = findSpecificGit(hints[currentHintIndex], onLookup) + .then(undefined, () => first); + + currentHintIndex++; + } + } else { + first = Promise.reject(null); + } + } else { + first = hints ? findSpecificGit(hints, onLookup) : Promise.reject(null); + } return first .then(undefined, () => { diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 80435de391a62..7cf04711cd75f 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -32,7 +32,7 @@ export async function deactivate(): Promise { } async function createModel(context: ExtensionContext, outputChannel: OutputChannel, telemetryReporter: TelemetryReporter, disposables: Disposable[]): Promise { - const pathHint = workspace.getConfiguration('git').get('path'); + const pathHint = workspace.getConfiguration('git').get('path'); const info = await findGit(pathHint, path => outputChannel.appendLine(localize('looking', "Looking for git in: {0}", path))); let env: any = {}; From 9df1e79180819f92eab92745f225f8c052260e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Thu, 10 Sep 2020 11:54:52 +0200 Subject: [PATCH 2/3] update `git.path` setting description --- extensions/git/package.nls.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 561f8c02f4b1b..28e72ec312b2b 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -84,7 +84,7 @@ "command.timelineCopyCommitId": "Copy Commit ID", "command.timelineCopyCommitMessage": "Copy Commit Message", "config.enabled": "Whether git is enabled.", - "config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows).", + "config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows). This can also be an array of string values containing multiple paths to look up.", "config.autoRepositoryDetection": "Configures when repositories should be automatically detected.", "config.autoRepositoryDetection.true": "Scan for both subfolders of the current opened folder and parent folders of open files.", "config.autoRepositoryDetection.false": "Disable automatic repository scanning.", From c228ad42f862e5c6ba28c5b71b41fccef3a09956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Thu, 10 Sep 2020 14:59:10 +0200 Subject: [PATCH 3/3] :lipstick: --- extensions/git/src/git.ts | 45 +++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 399e79f50d0af..2383e5cb40134 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -139,39 +139,28 @@ function findGitWin32(onLookup: (path: string) => void): Promise { .then(undefined, () => findGitWin32InPath(onLookup)); } -export function findGit(hints: string | string[] | undefined, onLookup: (path: string) => void): Promise { - let first: Promise; +export async function findGit(hint: string | string[] | undefined, onLookup: (path: string) => void): Promise { + const hints = Array.isArray(hint) ? hint : hint ? [hint] : []; - if (typeof hints === 'object') { - if (hints.length > 0) { - - first = findSpecificGit(hints[0], onLookup); - - let currentHintIndex = 1; - - while (currentHintIndex < hints.length) { - - first = findSpecificGit(hints[currentHintIndex], onLookup) - .then(undefined, () => first); + for (const hint of hints) { + try { + return await findSpecificGit(hint, onLookup); + } catch { + // noop + } + } - currentHintIndex++; - } - } else { - first = Promise.reject(null); + try { + switch (process.platform) { + case 'darwin': return await findGitDarwin(onLookup); + case 'win32': return await findGitWin32(onLookup); + default: return await findSpecificGit('git', onLookup); } - } else { - first = hints ? findSpecificGit(hints, onLookup) : Promise.reject(null); + } catch { + // noop } - return first - .then(undefined, () => { - switch (process.platform) { - case 'darwin': return findGitDarwin(onLookup); - case 'win32': return findGitWin32(onLookup); - default: return findSpecificGit('git', onLookup); - } - }) - .then(null, () => Promise.reject(new Error('Git installation not found.'))); + throw new Error('Git installation not found.'); } export interface IExecutionResult {