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
I am using GitPython both in windows and WSL and I noticed that paths are not handled coherently between the two (i.e. C:/ vs /mnt/c). It is possible to go around it most of the time using wslpath and converting from Windows to WSL and vice versa but it looks that the clone_from() ends up raising an exception regardless if the to_path is in WSL format or Windows format.
Steps to reproduce:
from pathlib import Path
import git
import traceback
import subprocess
def to_windows_path(wsl_path: Path) -> Path:
""" Converts a WSL path to windows path - works only if the WSL path actually exists """
wslpath_process = subprocess.run(['wslpath', '-w', wsl_path], text=True, capture_output=True)
return Path(wslpath_process.stdout.strip())
try:
git.Repo.clone_from('git@github.com:gitpython-developers/GitPython.git', Path.cwd() / 'gitpython')
except git.GitCommandError:
print(traceback.format_exc())
try:
git.Repo.clone_from('git@github.com:gitpython-developers/GitPython.git', to_windows_path(Path.cwd()) / 'gitpython')
except git.NoSuchPathError:
print(traceback.format_exc())
Expected behaviour:
When the script is launched from a python instance running on WSL the repo is cloned in $PWD/gitpython.
Actual behaviour:
[if (Path.cwd() / 'gitpython').exists() == False before running the script]
[git.version == '3.1.40']
python the_script.py
File ~/anaconda3/lib/python3.11/site-packages/git/repo/base.py:1244, in Repo._clone(cls, git, url, path, odb_default_type, progress, multi_options, allow_unsafe_protocols, allow_unsafe_options, **kwargs)
1241 if not osp.isabs(path):
1242 path = osp.join(git._working_dir, path) if git._working_dir is not None else path
-> 1244 repo = cls(path, odbt=odbt)
1246 # retain env values that were passed to _clone()
1247 repo.git.update_environment(**git.environment())
File ~/anaconda3/lib/python3.11/site-packages/git/repo/base.py:215, in Repo.init(self, path, odbt, search_parent_directories, expand_vars)
213 if epath is not None:
214 if not os.path.exists(epath):
--> 215 raise NoSuchPathError(epath)
217 ## Walk up the path to find the .git dir.
218 #
219 curpath = epath
NoSuchPathError: /mnt/c/Users/user.name/Documents/C:\Users\user.name\Documents/gitpython
The text was updated successfully, but these errors were encountered:
Even though I couldn't reproduce it, I wouldn't be surprised if something is going wrong here. It might be that it doesn't recognise the path as absolute, and makes it absolute by pre-pending the CWD all by itself (which it shouldn't have to do at all).
Indeed with relative paths it looks like it is working correctly, but still it would be nice if it worked correctly with absolute paths as well. In my project I think I will be able to get around this issue, but if I have time I will look into your repo and propose some changes!
Thanks!
I am using GitPython both in windows and WSL and I noticed that paths are not handled coherently between the two (i.e. C:/ vs /mnt/c). It is possible to go around it most of the time using
wslpath
and converting from Windows to WSL and vice versa but it looks that the clone_from() ends up raising an exception regardless if theto_path
is in WSL format or Windows format.Steps to reproduce:
Expected behaviour:
When the script is launched from a python instance running on WSL the repo is cloned in
$PWD/gitpython
.Actual behaviour:
The text was updated successfully, but these errors were encountered: