diff --git a/CHANGELOG.md b/CHANGELOG.md index 762287bd..a5725b94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#1023](https://github.com/estruyf/vscode-front-matter/issues/1023): Fix validation errors for image, file, and keywords fields - [#1024](https://github.com/estruyf/vscode-front-matter/issues/1024): Re-add the `frontMatter.copilot.enabled` setting to allow users to disable the GitHub Copilot integration +- Fix Git detection when Git is configured via VS Code `git.path` and not installed globally on the system ## [10.10.0] - 2026-04-03 - [Release notes](https://beta.frontmatter.codes/updates/v10.10.0) diff --git a/src/listeners/general/GitListener.ts b/src/listeners/general/GitListener.ts index 97fa8cd4..a453cfb4 100644 --- a/src/listeners/general/GitListener.ts +++ b/src/listeners/general/GitListener.ts @@ -26,7 +26,7 @@ import { import { GeneralCommands } from './../../constants/GeneralCommands'; import simpleGit, { SimpleGit } from 'simple-git'; import { Folders } from '../../commands/Folders'; -import { Event, commands, extensions } from 'vscode'; +import { Event, commands, extensions, workspace } from 'vscode'; import { GitAPIState, GitRepository, PostMessageData } from '../../models'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../localization'; @@ -343,7 +343,7 @@ export class GitListener { const options = { baseDir: submoduleFolder || wsFolder?.fsPath || '', - binary: 'git', + binary: GitListener.getGitBinary(), maxConcurrentProcesses: 6 }; @@ -356,6 +356,27 @@ export class GitListener { } } + /** + * Resolves the Git binary path from VS Code settings. + * Falls back to the default `git` command when no custom path is configured. + */ + private static getGitBinary(): string { + const gitPath = workspace.getConfiguration('git').get('path'); + + if (Array.isArray(gitPath)) { + const firstValidPath = gitPath.find((path) => typeof path === 'string' && path.trim()); + if (firstValidPath) { + return firstValidPath; + } + } + + if (typeof gitPath === 'string' && gitPath.trim()) { + return gitPath; + } + + return 'git'; + } + /** * Initializes the VS Code Git provider and sets up event listeners for repository changes. * @returns {Promise} A promise that resolves when the Git provider is initialized.