]> git.ipfire.org Git - thirdparty/git.git/commit
for-each-repo: work correctly in a worktree
authorDerrick Stolee <stolee@gmail.com>
Tue, 3 Mar 2026 17:31:53 +0000 (17:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Mar 2026 18:20:00 +0000 (10:20 -0800)
commit2ef539bceed75b54ea466537e5c26ebdf60f2bfc
treecbfd384b046d134be66b1cac0638813c4ea49e50
parent5f031fe4f14b5cc754daaf24534dbe0c6647fcca
for-each-repo: work correctly in a worktree

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).

We need to be careful to unset the local Git environment variables and
let the child process rediscover them, while also reinstating those
variables in the parent process afterwards. Update run_command_on_repo()
to use the new sanitize_repo_env() helper method to erase these
environment variables.

During review of this bug fix, there were several incorrect patches
demonstrating different bad behaviors. Most of these are covered by
tests, when it is not too expensive to set it up. One case that would be
expensive to set up is the GIT_NO_REPLACE_OBJECTS environment variable,
but we trust that using sanitize_repo_env() will be sufficient to
capture these uncovered cases by using the common code for resetting
environment variables.

Reported-by: Matthew Gabeler-Lee <fastcat@gmail.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/for-each-repo.c
t/t0068-for-each-repo.sh