@@ -140,7 +140,20 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
140
140
# removed. It's just cleaner.
141
141
if is_git_dir (curpath ):
142
142
self .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
+ self ._working_tree_dir = os .getenv ('GIT_WORK_TREE' ,self ._working_tree_dir )
144
157
break
145
158
146
159
dotgit = osp .join (curpath ,'.git' )