Skip to content

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

@SitiSchu

Description

@SitiSchu

search tried in the issue tracker

is:issue relpath

describe your issue

pre-commit will fail with ValueError: path is on mount 'C:', start on mount 'D:' when the config file is on C:\ but the git repository is on D:\

Steps to reproduce:

  • Create config file on your C: drive (for example %USERPROFILE%\.pre-commit-config.yaml)
  • Create git repo on D: drive
  • Run pre-commit: pre-commit run --config=%USERPROFILE%\.pre-commit-config.yaml

Commenting out line 164 in main.py (args.config = os.path.relpath(args.config)) fixes this issue. Is it necessary that the config path is relative to the working directory?

pre-commit --version

pre-commit 2.20.0

.pre-commit-config.yaml

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    -   id: trailing-whitespace

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 2.20.0
git --version: git version 2.36.1
sys.version:
    3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]
sys.executable: D:\temp\prctest\venv\Scripts\python.exe
os.name: nt
sys.platform: win32

error information

An unexpected error has occurred: ValueError: path is on mount 'C:', start on mount 'D:'
Traceback (most recent call last):
  File "D:\temp\prctest\venv\lib\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "D:\temp\prctest\venv\lib\site-packages\pre_commit\main.py", line 343, in main
    _adjust_args_and_chdir(args)
  File "D:\temp\prctest\venv\lib\site-packages\pre_commit\main.py", line 164, in _adjust_args_and_chdir
    args.config = os.path.relpath(args.config)
  File "D:\local_software\PYTHON\3.9.9\Windows_NT.x64\lib\ntpath.py", line 703, in relpath
    raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions