fix(utils): normalize MSYS Git paths + add MSYS CI repro - #12288
Conversation
Adds a windows-latest + msys2/setup-msys2 workflow that runs the real getGitRepoRoot under an MSYS shell where git rev-parse --show-toplevel returns /c/... paths. Without a fix this job is expected to fail with the drive-duplication ENOENT from facebook#11920.
On Windows under MSYS/Git Bash, git rev-parse --show-toplevel can return /c/... paths. Passing those to fs.realpath.native duplicates the drive letter (C:\c\...) and breaks eager Git VCS. Normalize the mount path first in getGitRepoRoot / getGitSuperProjectRoot, with unit tests for the conversion helper.
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
slorber
left a comment
There was a problem hiding this comment.
That's not good
Please don't use other bad PRs as inspiration for how to test this problem: the original issue reports running into this bug while running docusaurus build, not running new repro code you invent.
| @@ -0,0 +1,167 @@ | |||
| /** | |||
There was a problem hiding this comment.
I don't want to have this kind of repro file
The original issue reported the bug while running docusaurus build
Please remove this file and make sure docusaurus build actually fails the build under MSYS
You are even stealing code from someone else's PR:
https://github.com/facebook/docusaurus/pull/12067/changes#diff-74d42521dbbadfcfa9876bacdc56b9a6105b61125b7cc88e6f2a7d3ff6ca8694
This code is wrong, and stealing code from someone else is wrong too
| - name: Create git repo and run repro | ||
| shell: msys2 {0} | ||
| run: | | ||
| set -euo pipefail | ||
| REPO_DIR="/c/msys-repro-site" | ||
| rm -rf "$REPO_DIR" | ||
| mkdir -p "$REPO_DIR" | ||
| cd "$REPO_DIR" | ||
| git init -q | ||
| git config user.email repro@example.com | ||
| git config user.name Repro | ||
| echo "# repro" > README.md | ||
| git add README.md | ||
| git commit -q -m "initial commit" | ||
| echo "git rev-parse --show-toplevel => $(git rev-parse --show-toplevel)" | ||
|
|
||
| # Native Windows Node needs native Windows paths for the script and | ||
| # cwd. The git that getGitRepoRoot shells out to is still the MSYS | ||
| # git on PATH, so it keeps returning the `/c/...` MSYS path. | ||
| WORKSPACE_UNIX="$(cygpath -u "${GITHUB_WORKSPACE}")" | ||
| REPO_DIR_WIN="$(cygpath -w "$REPO_DIR")" | ||
| SCRIPT_WIN="$(cygpath -w "${WORKSPACE_UNIX}/admin/scripts/msys-git-path-repro/repro.mjs")" | ||
| echo "repo dir (win) : ${REPO_DIR_WIN}" | ||
| echo "script (win) : ${SCRIPT_WIN}" | ||
| node "${SCRIPT_WIN}" "${REPO_DIR_WIN}" |
There was a problem hiding this comment.
Please reproduce the bug using docusaurus build, not an artificial repro script
Pre-flight checklist
Motivation
Fixes #11920.
On Windows under Git Bash / MSYS / Cygwin,
git rev-parse --show-toplevelcan return a POSIX drive path such as/c/msys-repro-site.getGitRepoRootwas passing that straight tofs.realpath.native, which resolves it against the current drive root and duplicates the drive letter (C:\c\msys-repro-site), so the eager Git VCS path fails with ENOENT.What slorber asked for
Following #11920 (comment) and the review on #12067:
Commit / CI sequence
5506fca— workflow + repro script, no fixENOENT: realpath 'C:\c\msys-repro-site'withgitreturning/c/msys-repro-site44f7c32— normalize MSYS paths beforerealpathThe fix
gitPosixDrivePathToWindowsconverts/<drive>/...mount paths to native Windows paths onwin32beforefs.realpath.nativeingetGitRepoRootandgetGitSuperProjectRoot. Non-Windows platforms and non-drive POSIX paths are unchanged.Test plan
.github/workflows/msys-git-path-repro.ymlusingmsys2/setup-msys2, runsadmin/scripts/msys-git-path-repro/repro.mjsagainst the real compiledgetGitRepoRootgitUtils.test.ts@slorber — does this match what you wanted for the MSYS/Cygwin CI validation path?