Skip to content

Commit

Permalink
Allow pathlib.Path in Repo.__init__
Browse files Browse the repository at this point in the history
  • Loading branch information
oldPadavan authored and Byron committed Jul 15, 2018
1 parent 9807dd4 commit 7f08b77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
import gc
import gitdb

try:
import pathlib
except ImportError:
pathlib = None


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -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!!")
Expand Down
8 changes: 8 additions & 0 deletions git/test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f08b77

Please sign in to comment.