Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions packages/docusaurus-utils/src/vcs/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,28 @@ export async function isGitInsideWorktree(cwd: string): Promise<boolean> {
}
}

/**
* 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<string> {
const createErrorMessageBase = () => {
return `Couldn't find the git repository root directory
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down