Subject: Re: [PATCH v6 3/3] git-gui: handle GIT_DIR and GIT_WORK_TREE early

From: Aina Boot <[email-masked]>
Date: Sat, 9 May 2026 09:46:56 +0100

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