Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f08b77

Browse files
oldPadavanByron
authored andcommitted
Allow pathlib.Path in Repo.__init__
1 parent9807dd4 commit7f08b77

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

‎git/repo/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
importgc
3737
importgitdb
3838

39+
try:
40+
importpathlib
41+
exceptImportError:
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=epathorpathoros.getcwd()
124+
ifnotisinstance(epath,str):
125+
epath=str(epath)
119126
ifexpand_varsand ("%"inepathor"$"inepath):
120127
warnings.warn("The use of environment variables in paths is deprecated"+
121128
"\nfor security reasons and may be removed in the future!!")

‎git/test/test_repo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def test_repo_creation_from_different_paths(self, rw_repo):
110110
assertnotrw_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+
deftest_repo_creation_pathlib(self,rw_repo):
115+
ifpathlibisNone:# pythons bellow 3.4 don't have pathlib
116+
raiseSkipTest("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
deftest_description(self):
114122
txt="Test repository"
115123
self.rorepo.description=txt

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp