summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorBjörn Lässig <b.laessig@pengutronix.de>2018-09-28 19:32:00 +0200
committerSebastian Thiel <byronimo@gmail.com>2018-12-22 14:46:03 +0100
commit530ab00f28262f6be657b8ce7d4673131b2ff34a (patch)
treec63dfbca2dc804f989219c4c385fb6d02214136b /git
parent926d45b5fe1b43970fedbaf846b70df6c76727ea (diff)
downloadgitpython-530ab00f28262f6be657b8ce7d4673131b2ff34a.tar.gz
read workdir from git.config as referenced in man 1 git-config
Edited-by: Florian Scherf <f.scherf@pengutronix.de> added the remaining feedback in https://github.com/gitpython-developers/GitPython/pull/801/files
Diffstat (limited to 'git')
-rw-r--r--git/repo/base.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 3c5d6854..304faa76 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -140,7 +140,21 @@ class Repo(object):
# removed. It's just cleaner.
if is_git_dir(curpath):
self.git_dir = curpath
- self._working_tree_dir = os.getenv('GIT_WORK_TREE', os.path.dirname(self.git_dir))
+ # from man git-config : core.worktree
+ # Set the path to the root of the working tree. If GIT_COMMON_DIR environment
+ # variable is set, core.worktree is ignored and not used for determining the
+ # root of working tree. This can be overridden by the GIT_WORK_TREE environment
+ # variable. The value can be an absolute path or relative to the path to the .git
+ # directory, which is either specified by GIT_DIR, or automatically discovered.
+ # If GIT_DIR is specified but none of GIT_WORK_TREE and core.worktree is specified,
+ # the current working directory is regarded as the top level of your working tree.
+ self._working_tree_dir = os.path.dirname(self.git_dir)
+ if os.environ.get('GIT_COMMON_DIR') is None:
+ gitconf = self.config_reader("repository")
+ if gitconf.has_option('core', 'worktree'):
+ self._working_tree_dir = gitconf.get('core', 'worktree')
+ if 'GIT_WORK_TREE' in os.environ:
+ self._working_tree_dir = os.getenv('GIT_WORK_TREE')
break
dotgit = osp.join(curpath, '.git')