Skip to content

Commit fd9ba39

Browse files
committed
FIX gitpython-developers#535: expand also GIT_DIR var on Repo-construct
+ Improve documentation on the contructor `path` parameter.
1 parent aab7dc2 commit fd9ba39

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

git/repo/base.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
124124
repo = Repo("~/Development/git-python.git")
125125
repo = Repo("$REPOSITORIES/Development/git-python.git")
126126
127+
if `None, current-directory is used.
128+
The :envvar:`GIT_DIR` if set and not empty takes precendance over this parameter.
127129
:param odbt:
128130
Object DataBase type - a type which is constructed by providing
129131
the directory containing the database objects, i.e. .git/objects. It will
@@ -136,17 +138,18 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
136138
:raise InvalidGitRepositoryError:
137139
:raise NoSuchPathError:
138140
:return: git.Repo """
139-
epath = _expand_path(path or os.getcwd())
140-
self.git = None # should be set for __del__ not to fail in case we raise
141+
epath = os.getenv('GIT_DIR')
142+
epath = _expand_path(epath or path or os.getcwd())
141143
if not os.path.exists(epath):
142144
raise NoSuchPathError(epath)
143145

144146
self.working_dir = None
145147
self._working_tree_dir = None
146148
self.git_dir = None
147-
curpath = os.getenv('GIT_DIR', epath)
148149

149-
# walk up the path to find the .git dir
150+
## Walk up the path to find the `.git` dir.
151+
#
152+
curpath = epath
150153
while curpath:
151154
# ABOUT os.path.NORMPATH
152155
# It's important to normalize the paths, as submodules will otherwise initialize their

0 commit comments

Comments
 (0)