summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-19 15:49:13 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-19 15:56:28 +0200
commitb29388a8f9cf3522e5f52b47572af7d8f61862a1 (patch)
treee9e45fec9a6024b3dea56738cc6ff01ec8142c9e
parentaab7dc2c7771118064334ee475dff8a6bb176b57 (diff)
downloadgitpython-b29388a8f9cf3522e5f52b47572af7d8f61862a1.tar.gz
FIX #535: expand also GIT_DIR var on Repo-construct
+ Ignore "empty" GIT_DIR vars. + Improve documentation on the constructor `path` parameter.
-rw-r--r--git/repo/base.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index c5cdce7c..d36864bb 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -124,6 +124,8 @@ class Repo(object):
repo = Repo("~/Development/git-python.git")
repo = Repo("$REPOSITORIES/Development/git-python.git")
+ if `None, current-directory is used.
+ The :envvar:`GIT_DIR` if set and not empty takes precendance over this parameter.
:param odbt:
Object DataBase type - a type which is constructed by providing
the directory containing the database objects, i.e. .git/objects. It will
@@ -136,17 +138,19 @@ class Repo(object):
:raise InvalidGitRepositoryError:
:raise NoSuchPathError:
:return: git.Repo """
- epath = _expand_path(path or os.getcwd())
self.git = None # should be set for __del__ not to fail in case we raise
+ epath = os.getenv('GIT_DIR')
+ epath = _expand_path(epath or path or os.getcwd())
if not os.path.exists(epath):
raise NoSuchPathError(epath)
self.working_dir = None
self._working_tree_dir = None
self.git_dir = None
- curpath = os.getenv('GIT_DIR', epath)
- # walk up the path to find the .git dir
+ ## Walk up the path to find the `.git` dir.
+ #
+ curpath = epath
while curpath:
# ABOUT os.path.NORMPATH
# It's important to normalize the paths, as submodules will otherwise initialize their