Skip to content

Commit 7f08b77

Browse files
oldPadavanByron
authored andcommitted
Allow pathlib.Path in Repo.__init__
1 parent 9807dd4 commit 7f08b77

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: git/repo/base.py

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
import gc
3737
import gitdb
3838

39+
try:
40+
import pathlib
41+
except ImportError:
42+
pathlib = None
43+
3944

4045
log = logging.getLogger(__name__)
4146

@@ -116,6 +121,8 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
116121
epath = decygpath(epath)
117122

118123
epath = epath or path or os.getcwd()
124+
if not isinstance(epath, str):
125+
epath = str(epath)
119126
if expand_vars and ("%" in epath or "$" in epath):
120127
warnings.warn("The use of environment variables in paths is deprecated" +
121128
"\nfor security reasons and may be removed in the future!!")

Diff for: git/test/test_repo.py

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def test_repo_creation_from_different_paths(self, rw_repo):
110110
assert not rw_repo.git.working_dir.endswith('.git')
111111
self.assertEqual(r_from_gitdir.git.working_dir, rw_repo.git.working_dir)
112112

113+
@with_rw_repo('0.3.2.1')
114+
def test_repo_creation_pathlib(self, rw_repo):
115+
if pathlib is None: # pythons bellow 3.4 don't have pathlib
116+
raise SkipTest("pathlib was introduced in 3.4")
117+
118+
r_from_gitdir = Repo(pathlib.Path(rw_repo.git_dir))
119+
self.assertEqual(r_from_gitdir.git_dir, rw_repo.git_dir)
120+
113121
def test_description(self):
114122
txt = "Test repository"
115123
self.rorepo.description = txt

0 commit comments

Comments
 (0)