Skip to content

Commit 5d26325

Browse files
committed
Allow Pathlike paths when creating a git repo
1 parent ad1ae5f commit 5d26325

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

git/repo/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def __init__(
223223

224224
epath = epath or path or os.getcwd()
225225
if not isinstance(epath, str):
226-
epath = str(epath)
226+
epath = epath.__fspath__()
227227
if expand_vars and re.search(self.re_envvars, epath):
228228
warnings.warn(
229229
"The use of environment variables in paths is deprecated"

test/test_repo.py

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

6+
from dataclasses import dataclass
67
import gc
78
import glob
89
import io
@@ -105,6 +106,18 @@ def test_repo_creation_pathlib(self, rw_repo):
105106
r_from_gitdir = Repo(pathlib.Path(rw_repo.git_dir))
106107
self.assertEqual(r_from_gitdir.git_dir, rw_repo.git_dir)
107108

109+
@with_rw_repo("0.3.2.1")
110+
def test_repo_creation_pathlike(self, rw_repo):
111+
@dataclass
112+
class PathLikeMock:
113+
path: str
114+
115+
def __fspath__(self) -> str:
116+
return self.path
117+
118+
r_from_gitdir = Repo(PathLikeMock(rw_repo.git_dir))
119+
self.assertEqual(r_from_gitdir.git_dir, rw_repo.git_dir)
120+
108121
def test_description(self):
109122
txt = "Test repository"
110123
self.rorepo.description = txt

0 commit comments

Comments
 (0)