Skip to content

Commit c4e61ff

Browse files
committed
Fix relative GIT_DIR path bug, improve Cygwin/MSYS2 comment accuracy, set +x mode
- Use --absolute-git-dir instead of --git-dir to prevent lock-file check from resolving against CWD instead of REPO_DIR when invoked with an explicit path argument from a different working directory - Update detection comment to note /usr/bin/git also matches MSYS2 (non-MinGW) git, not just Cygwin - Set executable bit on the shell script (644 -> 755)
1 parent 8ca8896 commit c4e61ff

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

scripts/check-git-env.sh

100644100755
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ else
2727
echo "[INFO] git path: $GIT_PATH"
2828
echo "[INFO] git version: $GIT_VERSION"
2929

30-
# Detect Cygwin git — its path typically contains /cygdrive/ or /usr/bin/
31-
# and its version string includes "cygwin".
30+
# Detect Cygwin or MSYS2 (non-MinGW) git — path typically contains
31+
# /cygdrive/ or /usr/bin/. Git for Windows (MinGW) resolves to /mingw64/bin/git.
3232
case "$GIT_PATH" in
3333
/cygdrive/*|/usr/bin/git)
34-
echo "[WARN] git appears to be Cygwin git ($GIT_PATH)."
34+
echo "[WARN] git appears to be Cygwin or MSYS2 (non-MinGW) git ($GIT_PATH)."
3535
echo " This can cause signal errors and path translation issues."
3636
echo " Fix: add 'C:\\Program Files\\Git\\cmd' to the FRONT of your PATH,"
3737
echo " or set alias git='\"C:\\Program Files\\Git\\cmd\\git.exe\"' in your shell profile."
@@ -55,7 +55,9 @@ fi
5555
# ---------------------------------------------------------------------------
5656
# In worktrees, .git is a file pointing to the real git dir.
5757
# Use git rev-parse to find the actual git directory.
58-
GIT_DIR="$(git -C "$REPO_DIR" rev-parse --git-dir 2>/dev/null || echo "$REPO_DIR/.git")"
58+
# --absolute-git-dir (Git 2.13+) returns an absolute path, avoiding the bug
59+
# where a relative ".git" would resolve against CWD instead of REPO_DIR.
60+
GIT_DIR="$(git -C "$REPO_DIR" rev-parse --absolute-git-dir 2>/dev/null || echo "$REPO_DIR/.git")"
5961
LOCK_FILE="$GIT_DIR/index.lock"
6062

6163
if [ -f "$LOCK_FILE" ]; then

0 commit comments

Comments
 (0)