Skip to content

test: isolate the git client in tests from the calling repo - #24

Merged
Xe merged 1 commit into
mainfrom
Xe/isolate-test-gitconfig
Sep 29, 2026
Merged

Xe merged 1 commit into
mainfrom
Xe/isolate-test-gitconfig

Conversation

@Xe

@Xe Xe commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add internal/gittest.Isolate. It strips every GIT_* variable and points git at empty global and system config. TestMain in cmd/objgitd and internal/storage/tigris calls it.
  • Remove the per-helper config env from tryGit, gitSSHEnv, and gitOutput, and document the rule in AGENTS.md.

Details

The husky commit-msg hook runs go test, and git exports GIT_DIR and GIT_INDEX_FILE to hooks. The tests' git init --bare and git config user.* calls then wrote to the real repository. In a worktree, that is the shared .git/config: it got core.bare = true and a Test identity, and every worktree stopped working. GIT_CONFIG_GLOBAL=/dev/null did not help, because the repository config was the target.

Test plan

  • Code compiles with go build ./...
  • Code formatted with npm run format (goimports and gofmt are clean on changed files)
  • Manual testing: ran go test ./... with GIT_DIR pointed at a scratch worktree. On origin/main the scratch shared config got bare = true and tests failed. On this branch it stays unchanged and all tests pass.
  • TestIsolate covers main-checkout, worktree, and git -c hook environments. It fails without the fix.
  • This commit went through the real husky hook, and the shared config was not changed.

The husky commit-msg hook runs go test, and git exports GIT_DIR and
GIT_INDEX_FILE to hooks. The tests' git init and git config calls then
wrote to the repository that ran the hook. In a worktree that is the
shared .git/config, which got core.bare = true and a Test identity, and
every worktree stopped working.

Add internal/gittest.Isolate, which strips every GIT_* variable and
points git at empty global and system config. Call it from TestMain in
each package whose tests run the real git client.

Assisted-by: Claude Opus 5.5 via Claude Code
Signed-off-by: Xe Iaso <xe@tigrisdata.com>
@Xe
Xe merged commit 0418f93 into main Sep 29, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.13.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant