Repository navigation
Commit e264eaf
fix(index): pass a Windows hook outside the work tree by absolute path
On Windows, `run_commit_hook` runs an extensionless hook through Bash and
passes the hook's path relative to the working tree (`os.path.relpath`).
Bash resolves that path in its own view of the filesystem, which differs
from the Windows one across a mount point. Git for Windows mounts the
user's temporary directory as `/tmp` (`none /tmp usertemp` in its
`/etc/fstab`). For a repository under `%TEMP%` and a `core.hooksPath`
outside it, such as a global `~/.config/git/hooks`, Bash starts in
`/tmp/tmpXXXX/repo`, and `../../../../../.config/git/hooks/pre-commit`,
correct on the Windows side, leads to `/.config/git/hooks/pre-commit`.
Every commit then fails with exit code 127 and
`No such file or directory`.
A relative path that stays inside the working tree cannot cross such a
mount, so it is kept. A path that leaves the working tree (one starting
with `..`) is now passed as the absolute path in POSIX form (`C:/...`),
as is already done for a hook on another drive, when the Bash is Git for
Windows' own or one found on `PATH`: both accept it. The bare `bash.exe`
fallback may be the WSL launcher, which cannot open a Windows absolute
path, so it keeps the relative path as before.
`test_run_commit_hook_outside_worktree_on_windows` now checks the three
cases (outside the working tree with a found Bash, inside it, outside it
with the bare fallback), and `test_pre_commit_hook_outside_worktree` runs
a real hook through a `core.hooksPath` outside the working tree.
Validated on Windows 11 with Git for Windows 2.50.1 and Python 3.14:
`test/test_index.py` passes with an empty global Git configuration (183
passed, 3 skipped, 1 xpassed), and the new command-construction
assertion fails without the change; `ruff` 0.16.9 and `mypy` report no
issues on the changed files; a commit in a repository under `%TEMP%`,
with a global `core.hooksPath` holding a `pre-commit` hook, succeeds
instead of failing with exit code 127.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 563cb1f commit e264eaf
2 files changed
Lines changed: 64 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
201 | 206 | | |
202 | 207 | | |
203 | 208 | | |
204 | 209 | | |
205 | 210 | | |
206 | 211 | | |
207 | 212 | | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
214 | 223 | | |
215 | 224 | | |
216 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1513 | 1513 | | |
1514 | 1514 | | |
1515 | 1515 | | |
| 1516 | + | |
1516 | 1517 | | |
1517 | 1518 | | |
1518 | 1519 | | |
| |||
1521 | 1522 | | |
1522 | 1523 | | |
1523 | 1524 | | |
1524 | | - | |
1525 | | - | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
1526 | 1540 | | |
1527 | 1541 | | |
1528 | 1542 | | |
1529 | 1543 | | |
1530 | 1544 | | |
1531 | | - | |
1532 | | - | |
1533 | | - | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | | - | |
1541 | | - | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
1542 | 1556 | | |
1543 | 1557 | | |
1544 | 1558 | | |
| |||
1671 | 1685 | | |
1672 | 1686 | | |
1673 | 1687 | | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
1674 | 1710 | | |
1675 | 1711 | | |
1676 | 1712 | | |
| |||
0 commit comments