-
Notifications
You must be signed in to change notification settings - Fork 198
Description
Summary
Hello,
I've found an edge case on Windows where if you navigate to a git repository using a different case than the actual directory name (because Windows is case-insensitive) before installing prek, then prek install records the case that you used when navigating rather than the actual case in the hook's --cd argument. When you then go to make a commit to the repository, it fails becasue prek does a case-sensitive prefix comparison between this path and the output of git rev-parse --show-toplevel, which always returns the canonical casing. Since Windows filesystems are case-insensitive but not case-preserving in std::env::current_dir(), these two paths don't match and the commit fails:
(derzug) PS C:\testparent\testrepo> git commit -m "First"
Running in workspace: `C:\testparent\testrepo`
error: Failed to collect files
caused by: Workspace root `C:\testparent\testrepo` is not under git root `C:/TestParent/testrepo`
caused by: prefix not found
Steps to reproduce:
- Create a git repo under a mixed-case parent:
mkdir C:\TestParent\testrepo - Navigate using wrong casing on the parent:
cd C:\testparent\testrepo - Add a valid prek.toml and run
prek install - Attempt git commit
During step 3, I noticed that a hint gets issued that suggests this behavior is semi-intentional?
prek installed at `.git\hooks\pre-commit` for workspace `C:\testparent\testrepo`
hint: this hook installed for `C:\testparent\testrepo` only; run `prek install` from `C:/TestParent/testrepo` to install for the entire repo.
Suggested fix:
Either canonicalize the path (via std::fs::canonicalize() or equivalent) before writing it into the hook at install time, or use a case-insensitive comparison at commit time on Windows.
Willing to submit a PR?
- Yes — I’m willing to open a PR to fix this.
Platform
Windows 11
Version
prek 0.3.6 (dd53c3d 2026-03-16)
.pre-commit-config.yaml
None
Log file
2026-03-21T19:53:36.614909Z DEBUG prek: 0.3.6 (dd53c3d71 2026-03-16)
2026-03-21T19:53:36.615059Z DEBUG Changing current directory to: `C:\testparent\testrepo`
2026-03-21T19:53:36.615181Z DEBUG Args: ["C:\\Users\\mshaw\\Dropbox\\Python\\derzug\\.venv\\Scripts\\prek.exe", "hook-impl", "--hook-dir", "C:/TestParent/testrepo/.git/hooks", "--script-version", "4", "--hook-type=pre-commit", "--cd=C:\\testparent\\testrepo", "--"]
2026-03-21T19:53:36.715216Z TRACE get_root: close time.busy=99.1ms time.idle=20.9µs
2026-03-21T19:53:36.715314Z DEBUG Git root: C:/TestParent/testrepo
2026-03-21T19:53:36.715490Z DEBUG Found workspace root at `C:\testparent\testrepo`
2026-03-21T19:53:36.715513Z DEBUG Found project root at ``
2026-03-21T19:53:36.715633Z DEBUG Loading project configuration path=prek.toml
2026-03-21T19:53:36.718198Z TRACE Executing `C:\Program Files\Git\mingw64\libexec\git-core\git.exe ls-files --unmerged`
2026-03-21T19:53:36.763660Z DEBUG Found workspace root at `C:\testparent\testrepo`
2026-03-21T19:53:36.763737Z TRACE Include selectors: ``
2026-03-21T19:53:36.763758Z TRACE Skip selectors: ``
2026-03-21T19:53:36.764189Z DEBUG discover{root="C:\\testparent\\testrepo" config=None refresh=false}: Performing fresh workspace discovery
2026-03-21T19:53:36.764348Z TRACE discover{root="C:\\testparent\\testrepo" config=None refresh=false}:list_submodules{git_root="C:/TestParent/testrepo"}: close time.busy=36.9µs time.idle=2.60µs
2026-03-21T19:53:36.774924Z DEBUG Loading project configuration path=prek.toml
2026-03-21T19:53:36.782687Z TRACE discover{root="C:\\testparent\\testrepo" config=None refresh=false}: close time.busy=18.6ms time.idle=4.90µs
2026-03-21T19:53:36.782832Z TRACE Executing `C:\Program Files\Git\mingw64\libexec\git-core\git.exe diff --exit-code --name-only -z C:\testparent\testrepo\prek.toml`
2026-03-21T19:53:36.851851Z TRACE Checking lock resource="store" path=C:\Users\mshaw\AppData\Local\prek\.lock
2026-03-21T19:53:36.851917Z DEBUG Acquired lock resource="store"
2026-03-21T19:53:36.857357Z TRACE No requires-python found in pyproject.toml hook=check-yaml
2026-03-21T19:53:36.860521Z DEBUG Hooks going to run: ["check-yaml"]
2026-03-21T19:53:36.863642Z TRACE Executing `\\?\C:\Users\mshaw\AppData\Local\prek\hooks\python-4n6l5rAirdyuG6svTYxC\Scripts\python.exe -I -c import sys, json
info = {
"version": ".".join(map(str, sys.version_info[:3])),
"base_exec_prefix": sys.base_exec_prefix,
}
print(json.dumps(info))
[...]`
2026-03-21T19:53:36.987845Z DEBUG Found installed environment for hook `check-yaml` at `C:\Users\mshaw\AppData\Local\prek\hooks\python-4n6l5rAirdyuG6svTYxC`
2026-03-21T19:53:36.988706Z TRACE Released lock path=C:\Users\mshaw\AppData\Local\prek\.lock
2026-03-21T19:53:36.988783Z TRACE Executing `C:\Program Files\Git\mingw64\libexec\git-core\git.exe diff --diff-filter=A --name-only -z -- C:\testparent\testrepo`
2026-03-21T19:53:37.008005Z TRACE Executing `C:\Program Files\Git\mingw64\libexec\git-core\git.exe write-tree`
2026-03-21T19:53:37.026896Z TRACE Executing `C:\Program Files\Git\mingw64\libexec\git-core\git.exe diff-index --binary --exit-code a1c1d3ccbda68bebae55b0a759b1c4b0e634deff -- C:\testparent\testrepo`
2026-03-21T19:53:37.048273Z DEBUG Working tree is clean
2026-03-21T19:53:37.048346Z TRACE collect_files: close time.busy=10.3µs time.idle=2.60µs