From d7886b0752495405d77448bb94645d8afd4f8692 Mon Sep 17 00:00:00 2001 From: lsq Date: Thu, 19 Dec 2024 19:01:42 +0800 Subject: [PATCH] fix issue #217, Support cgywin/msys2 bash environment --- src/model/git.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/model/git.ts b/src/model/git.ts index 71d113b..997c420 100644 --- a/src/model/git.ts +++ b/src/model/git.ts @@ -26,7 +26,11 @@ export default class Git { public async getRepositoryRoot(repositoryPath: string): Promise { const result = await this.exec(repositoryPath, ['rev-parse', '--show-toplevel']) - return path.normalize(result.stdout.trim()) + let repoRootPath = path.normalize(result.stdout.trim()); + if (process.platform === 'win32' && repoRootPath .startsWith('\\') && !process.env.SHELL ) { + repoRootPath = repoRootPath.replace(/^\\([^\\]*)\\/, '$1:\\') + } + return repoRootPath; } public async exec(cwd: string, args: string[], options: SpawnOptions = {}): Promise> { @@ -83,7 +87,9 @@ export default class Git { options.env = Object.assign({}, process.env, options.env || {}, { LC_ALL: 'en_US.UTF-8', LANG: 'en_US.UTF-8' - }) + }) + + options.shell = options.env.SHELL? options.env.SHELL : (process.platform === 'win32' || !!options.shell); if (options.log !== false) { this.log(`> git ${args.join(' ')}\n`)