Re: [PATCH 2/2] for-each-repo: work correctly in a worktree
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Feb 24, 2026, 09:18 UTC
- Message-ID
- <aZ1s8y7f7PS7FVOG@pks.im>
- In-Reply-To
- <CAPig+cQcpJu_Z6VXbn5cee2AHmPHQaOLG39HFRG1SGnnY1cWFA@mail.gmail.com>
On Mon, Feb 23, 2026 at 10:34:30PM -0500, Eric Sunshine wrote:
Show 24 quoted lines
> [Cc:+peff] > > On Mon, Feb 23, 2026 at 10:32 PM Derrick Stolee via GitGitGadget > <gitgitgadget@gmail.com> wrote: > > When run in a worktree, the GIT_DIR directory is set in a different way > > than in a typical repository. Show this by updating t0068 to include a > > worktree and add a test that runs from that worktree. This requires > > moving the repo.key config into a global config instead of the base test > > repository's local config (demonstrating that it worked with > > non-worktree Git repositories). > > > > The fix is simple: unset the environment variable before looping over > > the repos. > > > > Signed-off-by: Derrick Stolee <stolee@gmail.com> > > --- > > diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c > > @@ -60,6 +61,9 @@ int cmd_for_each_repo(int argc, > > + /* Be sure to not pass GIT_DIR to children. */ > > + unsetenv(GIT_DIR_ENVIRONMENT); > > This only unsets GIT_DIR. Is that sufficient in the general case? > Elsewhere, we recommend[*] unsetting all of Git's local environment > variables.
Good question indeed. We have the `local_repo_env` array that contains all the environment variables that may influence repository discovery.
Patrick