Re: [PATCH 2/2] for-each-repo: work correctly in a worktree
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 24, 2026, 03:34 UTC
- Message-ID
- <CAPig+cQcpJu_Z6VXbn5cee2AHmPHQaOLG39HFRG1SGnnY1cWFA@mail.gmail.com>
- In-Reply-To
- <a47f9e9386badd83f0f5820f33f5eed68ca5fd82.1771903950.git.gitgitgadget@gmail.com>
[Cc:+peff]
On Mon, Feb 23, 2026 at 10:32 PM Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 16 quoted lines
> 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.
[*]: 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)`"