Skip to content

Commit c334da1

Browse files
whizsidjoaomoreno
andauthored
Multi git executable paths (#85954)
* Multi git executable path * update `git.path` setting description * 💄 Co-authored-by: João Moreno <[email protected]>
1 parent 3271ccc commit c334da1

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

extensions/git/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,8 @@
15151515
"git.path": {
15161516
"type": [
15171517
"string",
1518-
"null"
1518+
"null",
1519+
"array"
15191520
],
15201521
"markdownDescription": "%config.path%",
15211522
"default": null,

extensions/git/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"command.timelineCopyCommitId": "Copy Commit ID",
8585
"command.timelineCopyCommitMessage": "Copy Commit Message",
8686
"config.enabled": "Whether git is enabled.",
87-
"config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows).",
87+
"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.",
8888
"config.autoRepositoryDetection": "Configures when repositories should be automatically detected.",
8989
"config.autoRepositoryDetection.true": "Scan for both subfolders of the current opened folder and parent folders of open files.",
9090
"config.autoRepositoryDetection.false": "Disable automatic repository scanning.",

extensions/git/src/git.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,28 @@ function findGitWin32(onLookup: (path: string) => void): Promise<IGit> {
139139
.then(undefined, () => findGitWin32InPath(onLookup));
140140
}
141141

142-
export function findGit(hint: string | undefined, onLookup: (path: string) => void): Promise<IGit> {
143-
const first = hint ? findSpecificGit(hint, onLookup) : Promise.reject<IGit>(null);
144-
145-
return first
146-
.then(undefined, () => {
147-
switch (process.platform) {
148-
case 'darwin': return findGitDarwin(onLookup);
149-
case 'win32': return findGitWin32(onLookup);
150-
default: return findSpecificGit('git', onLookup);
151-
}
152-
})
153-
.then(null, () => Promise.reject(new Error('Git installation not found.')));
142+
export async function findGit(hint: string | string[] | undefined, onLookup: (path: string) => void): Promise<IGit> {
143+
const hints = Array.isArray(hint) ? hint : hint ? [hint] : [];
144+
145+
for (const hint of hints) {
146+
try {
147+
return await findSpecificGit(hint, onLookup);
148+
} catch {
149+
// noop
150+
}
151+
}
152+
153+
try {
154+
switch (process.platform) {
155+
case 'darwin': return await findGitDarwin(onLookup);
156+
case 'win32': return await findGitWin32(onLookup);
157+
default: return await findSpecificGit('git', onLookup);
158+
}
159+
} catch {
160+
// noop
161+
}
162+
163+
throw new Error('Git installation not found.');
154164
}
155165

156166
export interface IExecutionResult<T extends string | Buffer> {

extensions/git/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function deactivate(): Promise<any> {
3333
}
3434

3535
async function createModel(context: ExtensionContext, outputChannel: OutputChannel, telemetryReporter: TelemetryReporter, disposables: Disposable[]): Promise<Model> {
36-
const pathHint = workspace.getConfiguration('git').get<string>('path');
36+
const pathHint = workspace.getConfiguration('git').get<string | string[]>('path');
3737
const info = await findGit(pathHint, path => outputChannel.appendLine(localize('looking', "Looking for git in: {0}", path)));
3838

3939
const askpass = await Askpass.create(outputChannel, context.storagePath);

0 commit comments

Comments
 (0)