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

From: Derrick Stolee <[email-masked]>
Date: Wed, 25 Feb 2026 06:44:51 -0500

On 2/24/26 4:47 PM, Junio C Hamano wrote:

> Doesn't run_command() let you unsetenv in the child without
> affecting the parent process?
> 
> 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++;
	}

	child.git_cmd = 1;
	strvec_pushl(&child.args, "-C", abspath, NULL);

	for (i = 0; i < argc; i++)
		strvec_push(&child.args, argv[i]);

	free(abspath);

	return run_command(&child);
}

> Or is it essential to unset in both parent and child while the child
> is working and that is why we unset in the parent and then restore
> later?  I find this highly confusing.

Nope, not necessary to adjust it in the parent. The simpler version
above works in my test case. I'll apply it to an upcoming v3, but
will wait a couple of days to see if there is any more feedback on
this v2.5 before doing so.

Thanks,
-Stolee