Skip to content

Fix config path handling across Windows drives#3690

Closed
hansu650 wants to merge 1 commit into
pre-commit:mainfrom
hansu650:bug/config-path-different-drive
Closed

Fix config path handling across Windows drives#3690
hansu650 wants to merge 1 commit into
pre-commit:mainfrom
hansu650:bug/config-path-different-drive

Conversation

@hansu650
Copy link
Copy Markdown

Fixes #2530.

Summary

This fixes a Windows path handling error when --config points to a file on a different drive from the repository root.

os.path.relpath raises ValueError for paths on different Windows drives, so this keeps the original absolute path when a relative path cannot be computed.

Tests

Added a Windows regression test for --config on another drive.

Validation run locally:

python -m pytest tests/main_test.py -k different_drive
python -m pytest tests/main_test.py -k adjust_args_and_chdir
python -m pytest tests/main_test.py
python -m py_compile pre_commit/main.py tests/main_test.py
git diff --check

@asottile
Copy link
Copy Markdown
Member

ai slop is not acceptable

@asottile asottile closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ValueError on Windows when config is on a different drive than the git repo

2 participants