From: Eric Sunshine Date: Tue, 24 Feb 2026 03:34:30 GMT Subject: Re: [PATCH 2/2] for-each-repo: work correctly in a worktree Message-ID: In-Reply-To: [Cc:+peff] On Mon, Feb 23, 2026 at 10:32 PM Derrick Stolee via GitGitGadget 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 > --- > 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. [*]: From the "githooks" man page: "Environment variables, such as GIT_DIR, GIT_WORK_TREE, etc., are exported so that Git commands run by the hook can correctly locate the repository. If your hook needs to invoke Git commands in a foreign repository or in a different working tree of the same repository, then it should clear these environment variables so they do not interfere with Git operations at the foreign location. For example: `unset $(git rev-parse --local-env-vars)`"