Skip to content

Fix ValueError on Windows when config is on different drive than git repo#3660

Closed
avasis-ai wants to merge 1 commit intopre-commit:mainfrom
avasis-ai:fix-relpath-cross-drive-windows
Closed

Fix ValueError on Windows when config is on different drive than git repo#3660
avasis-ai wants to merge 1 commit intopre-commit:mainfrom
avasis-ai:fix-relpath-cross-drive-windows

Conversation

@avasis-ai
Copy link
Copy Markdown

Fixes #2530

On Windows, os.path.relpath() raises ValueError when the target path and the current working directory are on different drives (e.g., config on C: and repo on D:). This wraps all os.path.relpath() calls in _adjust_args_and_chdir with try/except ValueError, falling back to the absolute path when conversion is not possible.

As discussed in the issue, option 2 (try/except) was preferred by @asottile.

On Windows, os.path.relpath raises ValueError when the path and the
current working directory are on different drives. Wrap all relpath
calls in try/except to fall back to the absolute path.
@asottile
Copy link
Copy Markdown
Member

ai slop is not acceptable

@asottile asottile closed this Apr 19, 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

3 participants