51
51
__all__ = ('Repo' ,)
52
52
53
53
54
- def _expand_path (p , unsafe = True ):
55
- if unsafe :
56
- return osp . normpath ( osp . abspath ( osp . expandvars ( osp . expanduser ( p ))))
57
- else :
58
- return osp .normpath (osp .abspath (osp . expanduser ( p ) ))
54
+ def _expand_path (p , expand_vars = True ):
55
+ p = osp . expanduser ( p )
56
+ if expand_vars :
57
+ p = osp . expandvars ( p )
58
+ return osp .normpath (osp .abspath (p ))
59
59
60
60
61
61
class Repo (object ):
@@ -94,7 +94,7 @@ class Repo(object):
94
94
# Subclasses may easily bring in their own custom types by placing a constructor or type here
95
95
GitCommandWrapperType = Git
96
96
97
- def __init__ (self , path = None , odbt = DefaultDBType , search_parent_directories = False , unsafe = True ):
97
+ def __init__ (self , path = None , odbt = DefaultDBType , search_parent_directories = False , expand_vars = True ):
98
98
"""Create a new Repo instance
99
99
100
100
:param path:
@@ -120,15 +120,17 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
120
120
:raise InvalidGitRepositoryError:
121
121
:raise NoSuchPathError:
122
122
:return: git.Repo """
123
+
123
124
epath = path or os .getenv ('GIT_DIR' )
124
125
if not epath :
125
126
epath = os .getcwd ()
126
127
if Git .is_cygwin ():
127
128
epath = decygpath (epath )
128
- if unsafe and ("%" in epath or "$" in epath ):
129
- warnings .warn ("The use of environment variables in paths is deprecated"
130
- + "\n for security reasons and may be removed in the future!!" )
131
- epath = _expand_path (epath or path or os .getcwd (), unsafe )
129
+ epath = epath or path or os .getcwd ()
130
+ if expand_vars and ("%" in epath or "$" in epath ):
131
+ warnings .warn ("The use of environment variables in paths is deprecated" +
132
+ "\n for security reasons and may be removed in the future!!" )
133
+ epath = _expand_path (epath , expand_vars )
132
134
if not os .path .exists (epath ):
133
135
raise NoSuchPathError (epath )
134
136
@@ -155,7 +157,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
155
157
sm_gitpath = find_worktree_git_dir (dotgit )
156
158
157
159
if sm_gitpath is not None :
158
- self .git_dir = _expand_path (sm_gitpath , unsafe )
160
+ self .git_dir = _expand_path (sm_gitpath , expand_vars )
159
161
self ._working_tree_dir = curpath
160
162
break
161
163
@@ -851,7 +853,7 @@ def blame(self, rev, file, incremental=False, **kwargs):
851
853
return blames
852
854
853
855
@classmethod
854
- def init (cls , path = None , mkdir = True , odbt = DefaultDBType , ** kwargs ):
856
+ def init (cls , path = None , mkdir = True , odbt = DefaultDBType , expand_vars = True , ** kwargs ):
855
857
"""Initialize a git repository at the given path if specified
856
858
857
859
:param path:
@@ -869,7 +871,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
869
871
the directory containing the database objects, i.e. .git/objects.
870
872
It will be used to access all object data
871
873
872
- :param unsafe :
874
+ :param expand_vars :
873
875
if specified, environment variables will not be escaped. This
874
876
can lead to information disclosure, allowing attackers to
875
877
access the contents of environment variables
@@ -879,7 +881,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
879
881
880
882
:return: ``git.Repo`` (the newly created repo)"""
881
883
if path :
882
- path = _expand_path (path , unsafe )
884
+ path = _expand_path (path , expand_vars )
883
885
if mkdir and path and not osp .exists (path ):
884
886
os .makedirs (path , 0o755 )
885
887
0 commit comments