Skip to content

read workdir from git.config as referenced in man 1 git-config #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,20 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
# 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')
self._working_tree_dir = os.getenv('GIT_WORK_TREE', self._working_tree_dir)
break

dotgit = osp.join(curpath, '.git')
Expand Down