From aa0df78b2137b1ae4ad5eed2b1da84b9f682d7ab Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 15 Jan 2020 23:48:03 -0500 Subject: [PATCH] Fixes #932 - path issues with Git 2.25 on Windows https://github.com/git-for-windows/git/issues/2478 --- src/git/git.ts | 3 ++- src/system/string.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/git/git.ts b/src/git/git.ts index 4c8c1ab..35d714b 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -1018,7 +1018,8 @@ export namespace Git { export async function rev_parse__show_toplevel(cwd: string): Promise { const data = await git({ cwd: cwd, errors: GitErrorHandling.Ignore }, 'rev-parse', '--show-toplevel'); - return data.length === 0 ? undefined : data.trim(); + // Make sure to normalize: https://github.com/git-for-windows/git/issues/2478 + return data.length === 0 ? undefined : Strings.normalizePath(data.trim()); } export function shortlog(repoPath: string) { diff --git a/src/system/string.ts b/src/system/string.ts index 605a79d..a74e7cb 100644 --- a/src/system/string.ts +++ b/src/system/string.ts @@ -1,5 +1,6 @@ 'use strict'; import { createHash, HexBase64Latin1Encoding } from 'crypto'; +import { isWindows } from '../git/shell'; const emptyStr = ''; @@ -58,6 +59,7 @@ export namespace Strings { return secs * 1000 + Math.floor(nanosecs / 1000000); } + const driveLetterNormalizeRegex = /(?<=^\/?)([A-Z])(?=:\/)/; const pathNormalizeRegex = /\\/g; const pathStripTrailingSlashRegex = /\/$/g; const tokenRegex = /\$\{(\W*)?([^|]*?)(?:\|(\d+)(-|\?)?)?(\W*)?\}/g; @@ -149,6 +151,11 @@ export namespace Strings { normalized = `/${normalized}`; } + if (isWindows) { + // Ensure that drive casing is normalized (lower case) + normalized = normalized.replace(driveLetterNormalizeRegex, (drive: string) => drive.toLowerCase()); + } + return normalized; }