From 7f08b7730438bde34ae55bc3793fa524047bb804 Mon Sep 17 00:00:00 2001 From: oldPadavan Date: Thu, 12 Jul 2018 14:04:46 +0300 Subject: [PATCH] Allow pathlib.Path in Repo.__init__ --- git/repo/base.py | 7 +++++++ git/test/test_repo.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/git/repo/base.py b/git/repo/base.py index f8d670c4a..023582b56 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -36,6 +36,11 @@ import gc import gitdb +try: + import pathlib +except ImportError: + pathlib = None + log = logging.getLogger(__name__) @@ -116,6 +121,8 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal 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 8b43051ec..e65ead890 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -110,6 +110,14 @@ def test_repo_creation_from_different_paths(self, rw_repo): 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