@@ -140,7 +140,21 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
140140# removed. It's just cleaner.
141141if is_git_dir (curpath ):
142142self .git_dir = curpath
143- self ._working_tree_dir = os .getenv ('GIT_WORK_TREE' ,os .path .dirname (self .git_dir ))
143+ # from man git-config : core.worktree
144+ # Set the path to the root of the working tree. If GIT_COMMON_DIR environment
145+ # variable is set, core.worktree is ignored and not used for determining the
146+ # root of working tree. This can be overridden by the GIT_WORK_TREE environment
147+ # variable. The value can be an absolute path or relative to the path to the .git
148+ # directory, which is either specified by GIT_DIR, or automatically discovered.
149+ # If GIT_DIR is specified but none of GIT_WORK_TREE and core.worktree is specified,
150+ # the current working directory is regarded as the top level of your working tree.
151+ self ._working_tree_dir = os .path .dirname (self .git_dir )
152+ if os .environ .get ('GIT_COMMON_DIR' )is None :
153+ gitconf = self .config_reader ("repository" )
154+ if gitconf .has_option ('core' ,'worktree' ):
155+ self ._working_tree_dir = gitconf .get ('core' ,'worktree' )
156+ if 'GIT_WORK_TREE' in os .environ :
157+ self ._working_tree_dir = os .getenv ('GIT_WORK_TREE' )
144158break
145159
146160dotgit = osp .join (curpath ,'.git' )