Re: [PATCH v6 3/3] git-gui: handle GIT_DIR and GIT_WORK_TREE early
- From
- Aina Boot <bootaina702@gmail.com>
- Date
- May 9, 2026, 08:46 UTC
- Message-ID
- <20260509084846.1694-1-bootaina702@gmail.com>
- In-Reply-To
- <54d3c28a-040e-470c-b061-8d3a1cfe4257@gmail.com>
After observing, I’d like to propose a clearer way to manage GIT_WORK_TREE and GIT_DIR environment variables.
Five procedures in total: 1. set_worktree_env – sets GIT_WORK_TREE in the environment only if $_gitworktree is non-empty. 2. unset_worktree_env – safely unsets GIT_WORK_TREE (ignores if it’s not set). 3. clear_git_env – unsets both GIT_DIR and GIT_WORK_TREE before entering a submodule context. 4. capture_git_env – captures the current GIT_DIR and GIT_WORK_TREE values for later restoration. 5. restore_git_env – restores the saved values, setting GIT_WORK_TREE only if it was previously non-empty.
These would replace scattered, unguarded set/unset env(GIT_WORK_TREE) calls and ensure we don’t leave GIT_WORK_TREE defined when there is no actual worktree. It also makes the intention more explicit and reduces repetitive error-catching logic.
Aina