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

Commit6e8aa9b

Browse files
committed
Repo.init() now supports paths with a '~' in it, or environment variables in general.
Fixesgitpython-developers#83
1 parent96c6ab4 commit6e8aa9b

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

‎git/repo/base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
__all__= ('Repo', )
6767

6868

69+
def_expand_path(p):
70+
returnos.path.abspath(os.path.expandvars(os.path.expanduser(p)))
71+
72+
6973
classRepo(object):
7074

7175
"""Represents a git repository and allows you to query references,
@@ -111,7 +115,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
111115
:raise InvalidGitRepositoryError:
112116
:raise NoSuchPathError:
113117
:return: git.Repo """
114-
epath=os.path.abspath(os.path.expandvars(os.path.expanduser(pathoros.getcwd())))
118+
epath=_expand_path(pathoros.getcwd())
115119
self.git=None# should be set for __del__ not to fail in case we raise
116120
ifnotos.path.exists(epath):
117121
raiseNoSuchPathError(epath)
@@ -133,7 +137,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
133137
self.git_dir=gitpath
134138
self._working_tree_dir=curpath
135139
break
136-
140+
137141
ifnotsearch_parent_directories:
138142
break
139143
curpath,dummy=os.path.split(curpath)
@@ -700,7 +704,8 @@ def init(cls, path=None, mkdir=True, **kwargs):
700704
keyword arguments serving as additional options to the git-init command
701705
702706
:return: ``git.Repo`` (the newly created repo)"""
703-
707+
ifpath:
708+
path=_expand_path(path)
704709
ifmkdirandpathandnotos.path.exists(path):
705710
os.makedirs(path,0o755)
706711

‎git/repo/fun.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
fromgit.compatimportxrange
2020

2121

22-
__all__= ('rev_parse','is_git_dir','touch','find_git_dir','name_to_object','short_to_long','deref_tag',
22+
__all__= ('rev_parse','is_git_dir','touch','find_git_dir','name_to_object','short_to_long','deref_tag',
2323
'to_commit')
2424

2525

@@ -53,8 +53,10 @@ def find_git_dir(d):
5353
pass
5454
else:
5555
ifcontent.startswith('gitdir: '):
56-
d=join(dirname(d),content[8:])
57-
returnfind_git_dir(d)
56+
path=content[8:]
57+
ifnotos.path.isabs(path):
58+
path=join(dirname(d),path)
59+
returnfind_git_dir(path)
5860
# end handle exception
5961
returnNone
6062

‎git/test/test_repo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,16 @@ def test_comparison_and_hash(self):
383383
assertself.rorepo==self.rorepoandnot (self.rorepo!=self.rorepo)
384384
assertlen(set((self.rorepo,self.rorepo)))==1
385385

386+
@with_rw_directory
387+
deftest_tilde_in_repo_path(self,rw_dir):
388+
ph=os.environ['HOME']
389+
try:
390+
os.environ['HOME']=rw_dir
391+
Repo.init(os.path.join(rw_dir,'test.git'),bare=True)
392+
finally:
393+
os.environ['HOME']=ph
394+
# end assure HOME gets reset to what it was
395+
386396
deftest_git_cmd(self):
387397
# test CatFileContentStream, just to be very sure we have no fencepost errors
388398
# last \n is the terminating newline that it expects

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp