From 3759c0d49fc87671725f9d0eb57c0f8d17afd268 Mon Sep 17 00:00:00 2001 From: Kartik Sahu Date: Fri, 7 Aug 2026 20:07:08 +0530 Subject: [PATCH] fix(vcs): handle MSYS/Git Bash POSIX paths on Windows Fixes #11920%0A%0AGit on Windows (when using MSYS/Git Bash) returns POSIX-style paths like /p/projets/... which need to be converted to Windows paths like P:\projets\... before being used with fs.realpath()%0A%0AThis commit adds a normalizeMSYSPath() function that:%0A- Detects Windows platform%0A- Matches MSYS paths pattern (/[drive letter]/...)%0A- Converts to proper Windows format (DRIVE:\...)%0A- Applies the conversion in getGitRepoRoot() and getGitSuperProjectRoot()%0A%0AThis prevents 'ENOENT: no such file or directory' errors when building Docusaurus sites on Windows with Git Bash. --- packages/docusaurus-utils/src/vcs/gitUtils.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-utils/src/vcs/gitUtils.ts b/packages/docusaurus-utils/src/vcs/gitUtils.ts index 46b19eddf9b7..e7f462070e98 100644 --- a/packages/docusaurus-utils/src/vcs/gitUtils.ts +++ b/packages/docusaurus-utils/src/vcs/gitUtils.ts @@ -275,6 +275,28 @@ export async function isGitInsideWorktree(cwd: string): Promise { } } +/** + * Normalizes MSYS/Git Bash paths on Windows from POSIX format to Windows format. + * For example: /c/Users/... -> C:\Users\... + * This fixes issues where Git on Windows (via MSYS/Git Bash) returns POSIX-style paths. + */ +function normalizeMSYSPath(gitPath: string): string { + // Only apply on Windows + if (process.platform !== 'win32') { + return gitPath; + } + + // Match MSYS-style paths like /c/..., /d/..., /p/... etc. + const msysMatch = gitPath.match(/^\/([a-z])\/(.*)$/i); + if (msysMatch) { + const driveLetter = msysMatch[1]!.toUpperCase(); + const restOfPath = msysMatch[2]!.replace(/\//g, '\\'); + return `${driveLetter}:\\${restOfPath}`; + } + + return gitPath; +} + export async function getGitRepoRoot(cwd: string): Promise { const createErrorMessageBase = () => { return `Couldn't find the git repository root directory @@ -303,7 +325,10 @@ The command returned exit code ${logger.code(result.exitCode)}: ${logger.subdue( ); } - return fs.realpath.native(result.stdout.trim()); + const gitPath = result.stdout.trim(); + // Normalize MSYS paths before passing to fs.realpath + const normalizedPath = normalizeMSYSPath(gitPath); + return fs.realpath.native(normalizedPath); } // A Git "superproject" is a Git repository that contains submodules @@ -347,7 +372,8 @@ The command returned exit code ${logger.code(result.exitCode)}: ${logger.subdue( // this command only works when inside submodules // otherwise it doesn't return anything when we are inside the main repo if (output) { - return fs.realpath.native(output); + const normalizedOutput = normalizeMSYSPath(output); + return fs.realpath.native(normalizedOutput); } return getGitRepoRoot(cwd); }