summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroldPadavan <evggoncharov@gmail.com>2018-07-12 14:04:46 +0300
committerSebastian Thiel <byronimo@gmail.com>2018-07-15 14:26:15 +0200
commit7f08b7730438bde34ae55bc3793fa524047bb804 (patch)
tree0f6a64a7ce6db109c4ea2884e1a850757177436b
parent9807dd48b73ec43b21aa018bdbf591af4a3cc5f9 (diff)
downloadgitpython-7f08b7730438bde34ae55bc3793fa524047bb804.tar.gz
Allow pathlib.Path in Repo.__init__
-rw-r--r--git/repo/base.py7
-rw-r--r--git/test/test_repo.py8
2 files changed, 15 insertions, 0 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index f8d670c4..023582b5 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -36,6 +36,11 @@ from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch, find_work
import gc
import gitdb
+try:
+ import pathlib
+except ImportError:
+ pathlib = None
+
log = logging.getLogger(__name__)
@@ -116,6 +121,8 @@ class Repo(object):
epath = decygpath(epath)
epath = epath or path or os.getcwd()
+ if not isinstance(epath, str):
+ epath = str(epath)
if expand_vars and ("%" in epath or "$" in epath):
warnings.warn("The use of environment variables in paths is deprecated" +
"\nfor security reasons and may be removed in the future!!")
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 8b43051e..e65ead89 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -110,6 +110,14 @@ class TestRepo(TestBase):
assert not rw_repo.git.working_dir.endswith('.git')
self.assertEqual(r_from_gitdir.git.working_dir, rw_repo.git.working_dir)
+ @with_rw_repo('0.3.2.1')
+ def test_repo_creation_pathlib(self, rw_repo):
+ if pathlib is None: # pythons bellow 3.4 don't have pathlib
+ raise SkipTest("pathlib was introduced in 3.4")
+
+ r_from_gitdir = Repo(pathlib.Path(rw_repo.git_dir))
+ self.assertEqual(r_from_gitdir.git_dir, rw_repo.git_dir)
+
def test_description(self):
txt = "Test repository"
self.rorepo.description = txt