From 530ab00f28262f6be657b8ce7d4673131b2ff34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20L=C3=A4ssig?= Date: Fri, 28 Sep 2018 19:32:00 +0200 Subject: read workdir from git.config as referenced in man 1 git-config Edited-by: Florian Scherf added the remaining feedback in https://github.com/gitpython-developers/GitPython/pull/801/files --- git/repo/base.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'git') 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') -- cgit v1.2.3