From 880064b9870e6b494fb06d6fb95c8559d61f6f39 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 25 May 2026 15:16:25 +0200 Subject: [PATCH] Use the isolated test env for shell commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shell.RunShellCommand was passing os.Environ() to its child, while its sibling runCommandWithOutputAndEnv has used the minimal NewTestEnvironment since late 2023 when env isolation was introduced; the sh path was just missed. This matters when integration tests run from inside a `git rebase -x` exec in a linked worktree: git sets GIT_DIR=
/.git/worktrees/ for the exec, and it leaks all the way down through bash, just, go test, and the test process, into every git invocation RunShellCommand spawns. cmd.Dir becomes irrelevant — git resolves GIT_DIR over cwd-based discovery, with the work-tree taken from the gitdir file (i.e. the worktree root). So `git checkout -b conflict` in a test fixture creates the branch on the real worktree and switches its HEAD, hijacking the in-progress rebase and trashing the working tree. (In the main worktree git doesn't set GIT_DIR for rebase exec, which is why the bug was only visible from linked worktrees.) Using self.env also incidentally restores GIT_CONFIG_GLOBAL for shell commands, so commits made via RunShellCommand are now authored by the test config's CI identity rather than whatever the host's ~/.gitconfig resolves to. --- pkg/integration/components/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 2e5fa01ce..70b12146a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -77,7 +77,7 @@ func (self *Shell) RunShellCommand(cmdStr string) *Shell { } cmd := exec.Command(shell, shellArg, cmdStr) - cmd.Env = os.Environ() + cmd.Env = self.env cmd.Dir = self.dir output, err := cmd.CombinedOutput()