Subject: Re: [PATCH 2/2] for-each-repo: work correctly in a worktree

From: Patrick Steinhardt <[email-masked]>
Date: Tue, 24 Feb 2026 10:18:43 +0100

On Mon, Feb 23, 2026 at 10:34:30PM -0500, Eric Sunshine wrote:
> [Cc:+peff]
> 
> On Mon, Feb 23, 2026 at 10:32 PM Derrick Stolee via GitGitGadget
> <[email-masked]> 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 <[email-masked]>
> > ---
> > 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