Skip to content

Commit b1795c3

Browse files
committed
Fixed missing parameter and changed name
1 parent 90f5f75 commit b1795c3

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

git/repo/base.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
__all__ = ('Repo',)
5252

5353

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))
5959

6060

6161
class Repo(object):
@@ -94,7 +94,7 @@ class Repo(object):
9494
# Subclasses may easily bring in their own custom types by placing a constructor or type here
9595
GitCommandWrapperType = Git
9696

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):
9898
"""Create a new Repo instance
9999
100100
:param path:
@@ -120,15 +120,17 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
120120
:raise InvalidGitRepositoryError:
121121
:raise NoSuchPathError:
122122
:return: git.Repo """
123+
123124
epath = path or os.getenv('GIT_DIR')
124125
if not epath:
125126
epath = os.getcwd()
126127
if Git.is_cygwin():
127128
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-
+ "\nfor 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+
"\nfor security reasons and may be removed in the future!!")
133+
epath = _expand_path(epath, expand_vars)
132134
if not os.path.exists(epath):
133135
raise NoSuchPathError(epath)
134136

@@ -155,7 +157,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
155157
sm_gitpath = find_worktree_git_dir(dotgit)
156158

157159
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)
159161
self._working_tree_dir = curpath
160162
break
161163

@@ -851,7 +853,7 @@ def blame(self, rev, file, incremental=False, **kwargs):
851853
return blames
852854

853855
@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):
855857
"""Initialize a git repository at the given path if specified
856858
857859
:param path:
@@ -869,7 +871,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
869871
the directory containing the database objects, i.e. .git/objects.
870872
It will be used to access all object data
871873
872-
:param unsafe:
874+
:param expand_vars:
873875
if specified, environment variables will not be escaped. This
874876
can lead to information disclosure, allowing attackers to
875877
access the contents of environment variables
@@ -879,7 +881,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
879881
880882
:return: ``git.Repo`` (the newly created repo)"""
881883
if path:
882-
path = _expand_path(path, unsafe)
884+
path = _expand_path(path, expand_vars)
883885
if mkdir and path and not osp.exists(path):
884886
os.makedirs(path, 0o755)
885887

0 commit comments

Comments
 (0)