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

From: Jeff King <[email-masked]>
Date: Wed, 25 Feb 2026 08:13:44 -0500

On Wed, Feb 25, 2026 at 06:44:51AM -0500, Derrick Stolee wrote:

> > Looking at run-command.c:prep_childenv(), it seems that you can pass
> > "VAR=VAL" to "export VAR=VAL" in the child, and pass "VAR" to "unset
> > VAR" in the child.
> 
> You're right. Here's a much simpler implementation:
> 
> static int run_command_on_repo(const char *path, int argc, const char ** argv)
> {
> 	int i = 0;
> 	struct child_process child = CHILD_PROCESS_INIT;
> 	char *abspath = interpolate_path(path, 0);
> 
> 	while (local_repo_env[i]) {
> 		strvec_push(&child.env, local_repo_env[i]);
> 		i++;
> 	}

You can actually just use strvec_pushv() to do this as a one-liner
(though annoyingly you need a cast because of how const works; you can
easily find an example with grep).

But I really think you should consider keeping config-related variables
in place, as prepare_other_repo_env() does. Otherwise something like:

  git -c pack.threads=1 for-each-repo repack -ad

will ignore that config in the sub-processes (whereas it currently is
respected).

And for that, you do need to loop yourself.

-Peff