Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit24abf10

Browse files
committed
Allow Pathlike urls and destinations when cloning
1 parente3f38ff commit24abf10

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

‎git/repo/base.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,10 @@ def _clone(
13621362
odbt=kwargs.pop("odbt",odb_default_type)
13631363

13641364
# When pathlib.Path or other class-based path is passed
1365+
ifnotisinstance(url,str):
1366+
url=url.__fspath__()
13651367
ifnotisinstance(path,str):
1366-
path=str(path)
1368+
path=path.__fspath__()
13671369

13681370
## A bug win cygwin's Git, when `--bare` or `--separate-git-dir`
13691371
# it prepends the cwd or(?) the `url` into the `path, so::
@@ -1380,7 +1382,7 @@ def _clone(
13801382
multi=shlex.split(" ".join(multi_options))
13811383

13821384
ifnotallow_unsafe_protocols:
1383-
Git.check_unsafe_protocols(str(url))
1385+
Git.check_unsafe_protocols(url)
13841386
ifnotallow_unsafe_options:
13851387
Git.check_unsafe_options(options=list(kwargs.keys()),unsafe_options=cls.unsafe_git_clone_options)
13861388
ifnotallow_unsafe_optionsandmulti_options:

‎test/test_clone.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This module is part of GitPython and is released under the
22
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
33

4+
fromdataclassesimportdataclass
45
importos
56
importos.pathasosp
67
importpathlib
@@ -45,7 +46,20 @@ def test_checkout_in_non_empty_dir(self, rw_dir):
4546
deftest_clone_from_pathlib(self,rw_dir):
4647
original_repo=Repo.init(osp.join(rw_dir,"repo"))
4748

48-
Repo.clone_from(original_repo.git_dir,pathlib.Path(rw_dir)/"clone_pathlib")
49+
Repo.clone_from(pathlib.Path(original_repo.git_dir),pathlib.Path(rw_dir)/"clone_pathlib")
50+
51+
@with_rw_directory
52+
deftest_clone_from_pathlike(self,rw_dir):
53+
original_repo=Repo.init(osp.join(rw_dir,"repo"))
54+
55+
@dataclass
56+
classPathLikeMock:
57+
path:str
58+
59+
def__fspath__(self)->str:
60+
returnself.path
61+
62+
Repo.clone_from(PathLikeMock(original_repo.git_dir),PathLikeMock(os.path.join(rw_dir,"clone_pathlike")))
4963

5064
@with_rw_directory
5165
deftest_clone_from_pathlib_withConfig(self,rw_dir):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp