You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pre-commit install fails on Windows network mount drive #1802
Hi, I'm trying to help some team members set up pre-commit on a Windows network mount drive, and they're encountering an issue with paths. Seems related to this comment in #1610, which seems to be a different issue than the one the original issue, as we are on the most recent version of pre-commit and git, and the fix that was merged in #1727 for that doesn't seem to address this issue. I also tried other versions of Git for Windows <2.25, and the issue still seemed to persist.
I tested the solution that @christopherdoyle proposed, and that does seems to fix this issue with network mount drives, though I saw that @asottile would prefer not to use pathlib. I am not able to propose a fix right now, but I wanted to raise this as an issue that still exists.
Full error below:
### version information
```
pre-commit version: 2.10.1
sys.version:
3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:29:07) [MSC v.1916 64 bit (AMD64)]
sys.executable: C:\Users\roderick\.conda\envs\nmt\python.exe
os.name: nt
sys.platform: win32
```
### error information
```
An unexpected error has occurred: ValueError: path is on mount 'S:', start on mount '\\\\MyServer\Directory'
```
```
Traceback (most recent call last):
File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\error_handler.py", line 65, in error_handler
yield
File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\main.py", line 333, in main
_adjust_args_and_chdir(args)
File "C:\Users\roderick\.conda\envs\nmt\lib\site-packages\pre_commit\main.py", line 153, in _adjust_args_and_chdir
args.config = os.path.relpath(args.config)
File "C:\Users\roderick\.conda\envs\nmt\lib\ntpath.py", line 703, in relpath
raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'S:', start on mount '\\\\MyServer\Directory'
can you provide a reproduction and/or more information? might need to use the debugger a bit to see what git is telling us and why we can't deal with that
Taking a look at the code I'd guess that the problem is caused by the os.path.realpath on git.get_root function. It converts a substed or mounted drive to its original path.
Sorry. I'm sure realpath convert between substed drives. What I was saying is that I'm guessing that this is the root of the problem (I don't know that if it's just a case of replacing realpath by abspath).
Hi @asottile, sorry I'm new to this and not exactly sure what you want me to do.
I can reproduce this bug by running pre-commit run. I cloned the pre-commit repo and set up a test environment, and I can reproduce the error by running the main.py script as well, but I don't exactly how to see what git is saying, as you suggested. What I can see is that this block:
os.path.realpath(path)
Return the canonical path of the specified filename, eliminating any symbolic links encountered in the path (if they are supported by the operating system).
Note When symbolic link cycles occur, the returned path will be one member of the cycle, but no guarantee is made about which member that will be.
Changed in version 3.6: Accepts a path-like object.
Changed in version 3.8: Symbolic links and junctions are now resolved on Windows.
Activity
asottile commentedon Feb 17, 2021
can you provide a reproduction and/or more information? might need to use the debugger a bit to see what
gitis telling us and why we can't deal with thatigortg commentedon Feb 20, 2021
Same issue here using a substed drive. Here I use a substed drive
W:pointing to a subfolder onD:Output of
git rev-parse --show-toplevelis the path to the original subfolder (notW:)asottile commentedon Feb 20, 2021
pre-commit no longer uses
git rev-parse --show-toplevel, so I'm confused why you're still seeing these issuesigortg commentedon Feb 21, 2021
Sorry, I did the comment based on old versions.
Taking a look at the code I'd guess that the problem is caused by the
os.path.realpathongit.get_rootfunction. It converts a substed or mounted drive to its original path.asottile commentedon Feb 21, 2021
instead of guessing can you show me in a terminal? as far as I know realpath does not translate across mounts
igortg commentedon Feb 21, 2021
Sorry. I'm sure
realpathconvert between substed drives. What I was saying is that I'm guessing that this is the root of the problem (I don't know that if it's just a case of replacingrealpathbyabspath).goroderickgo commentedon Feb 23, 2021
Hi @asottile, sorry I'm new to this and not exactly sure what you want me to do.
I can reproduce this bug by running
pre-commit run. I cloned thepre-commitrepo and set up a test environment, and I can reproduce the error by running themain.pyscript as well, but I don't exactly how to see whatgitis saying, as you suggested. What I can see is that this block:in the
git.get_root()function returns the path as\\\\MyServer\Directorywhereasargs.configis located atS:\path\to\.pre-commit-config.yamlfaph commentedon Feb 23, 2021
Just to add that we're seeing the same error using Python 3.8.6
With Python 3.6.8, all works as expected.
faph commentedon Feb 23, 2021
From the docs (https://docs.python.org/3/library/os.path.html#os.path.realpath):
asottile commentedon Feb 24, 2021
can you try out the branch in #1814 -- I tried using
abspathinstead ofrealpath-- that should probably fix this problem ?igortg commentedon Feb 25, 2021
That fixed for me. Many thanks
goroderickgo commentedon Feb 26, 2021
Yep, also works for me. Thanks for the quick fix!