Title: git.Repo.clone_from() not working correctly in WSL · Issue #1902 · gitpython-developers/GitPython · GitHub
Open Graph Title: git.Repo.clone_from() not working correctly in WSL · Issue #1902 · gitpython-developers/GitPython
X Title: git.Repo.clone_from() not working correctly in WSL · Issue #1902 · gitpython-developers/GitPython
Description: 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 v...
Open Graph Description: 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 ...
X Description: 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 ...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1902
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"git.Repo.clone_from() not working correctly in WSL","articleBody":"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.\r\n\r\nSteps to reproduce:\r\n```\r\nfrom pathlib import Path\r\nimport git\r\nimport traceback\r\nimport subprocess\r\n\r\ndef to_windows_path(wsl_path: Path) -\u003e Path:\r\n \"\"\" Converts a WSL path to windows path - works only if the WSL path actually exists \"\"\"\r\n wslpath_process = subprocess.run(['wslpath', '-w', wsl_path], text=True, capture_output=True)\r\n return Path(wslpath_process.stdout.strip())\r\n\r\ntry:\r\n git.Repo.clone_from('git@github.com:gitpython-developers/GitPython.git', Path.cwd() / 'gitpython')\r\nexcept git.GitCommandError:\r\n print(traceback.format_exc())\r\n\r\ntry:\r\n git.Repo.clone_from('git@github.com:gitpython-developers/GitPython.git', to_windows_path(Path.cwd()) / 'gitpython')\r\nexcept git.NoSuchPathError:\r\n print(traceback.format_exc())\r\n```\r\n\r\nExpected behaviour:\r\nWhen the script is launched from a python instance running on WSL the repo is cloned in `$PWD/gitpython`.\r\n\r\nActual behaviour:\r\n\u003e [if (Path.cwd() / 'gitpython').exists() == False before running the script]\r\n\u003e [git.__version__ == '3.1.40']\r\n\u003e python the_script.py\r\n\r\n\u003e File ~/anaconda3/lib/python3.11/site-packages/git/repo/base.py:1328, in Repo.clone_from(cls, url, to_path, progress, env, multi_options, allow_unsafe_protocols, allow_unsafe_options, **kwargs)\r\n\u003e 1326 if env is not None:\r\n\u003e 1327 git.update_environment(**env)\r\n\u003e -\u003e 1328 return cls._clone(\r\n\u003e 1329 git,\r\n\u003e 1330 url,\r\n\u003e 1331 to_path,\r\n\u003e 1332 GitCmdObjectDB,\r\n\u003e 1333 progress,\r\n\u003e 1334 multi_options,\r\n\u003e 1335 allow_unsafe_protocols=allow_unsafe_protocols,\r\n\u003e 1336 allow_unsafe_options=allow_unsafe_options,\r\n\u003e 1337 **kwargs,\r\n\u003e 1338 )\r\n\u003e \r\n\u003e 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)\r\n\u003e 1241 if not osp.isabs(path):\r\n\u003e 1242 path = osp.join(git._working_dir, path) if git._working_dir is not None else path\r\n\u003e -\u003e 1244 repo = cls(path, odbt=odbt)\r\n\u003e 1246 # retain env values that were passed to _clone()\r\n\u003e 1247 repo.git.update_environment(**git.environment())\r\n\u003e \r\n\u003e File ~/anaconda3/lib/python3.11/site-packages/git/repo/base.py:215, in Repo.__init__(self, path, odbt, search_parent_directories, expand_vars)\r\n\u003e 213 if epath is not None:\r\n\u003e 214 if not os.path.exists(epath):\r\n\u003e --\u003e 215 raise NoSuchPathError(epath)\r\n\u003e 217 ## Walk up the path to find the `.git` dir.\r\n\u003e 218 #\r\n\u003e 219 curpath = epath\r\n\u003e NoSuchPathError: /mnt/c/Users/user.name/Documents/C:\\Users\\user.name\\Documents/gitpython","author":{"url":"https://github.com/paolzpk","@type":"Person","name":"paolzpk"},"datePublished":"2024-04-15T15:18:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/1902/GitPython/issues/1902"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:81bcbcf8-19ca-47e1-3c26-3e7dc15883b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CD4:2A0665:70632:95606:6A4C1B76 |
| html-safe-nonce | e42749128526a8e4c42a19280b11dfe334b4f5e6c416fc3606a0b3c9d8e102c6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0Q0OjJBMDY2NTo3MDYzMjo5NTYwNjo2QTRDMUI3NiIsInZpc2l0b3JfaWQiOiI3MDIyMjg5NjI1NDQwNTkwNzEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e71ce10cdeb6cddbd57dfd9f97281a460fbbf136b5dc4819e9eb170a6715e4bc |
| hovercard-subject-tag | issue:2243948431 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1902/issue_layout |
| twitter:image | https://opengraph.githubassets.com/80d5df62c6f48f3d1ffb1f35244d0c3a40a97657c3abc89499635e667283a73d/gitpython-developers/GitPython/issues/1902 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/80d5df62c6f48f3d1ffb1f35244d0c3a40a97657c3abc89499635e667283a73d/gitpython-developers/GitPython/issues/1902 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | paolzpk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0ccfc9e5281bfe12e38a4d632dc422843e4d5b6757917f7efda2f6567d72fea9 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 17b2c8bc78100cad23202aad2074e77ead6bd1d6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width