summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/repo/base.py')
-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')