Repository navigation
test: isolate the git client in tests from the calling repo - #24
Merged
Merged
Conversation
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>
|
🎉 This PR is included in version 1.13.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
internal/gittest.Isolate. It strips everyGIT_*variable and points git at empty global and system config.TestMainincmd/objgitdandinternal/storage/tigriscalls it.tryGit,gitSSHEnv, andgitOutput, and document the rule inAGENTS.md.Details
The husky
commit-msghook runsgo test, and git exportsGIT_DIRandGIT_INDEX_FILEto hooks. The tests'git init --bareandgit config user.*calls then wrote to the real repository. In a worktree, that is the shared.git/config: it gotcore.bare = trueand aTestidentity, and every worktree stopped working.GIT_CONFIG_GLOBAL=/dev/nulldid not help, because the repository config was the target.Test plan
go build ./...npm run format(goimports and gofmt are clean on changed files)go test ./...withGIT_DIRpointed at a scratch worktree. Onorigin/mainthe scratch shared config gotbare = trueand tests failed. On this branch it stays unchanged and all tests pass.TestIsolatecovers main-checkout, worktree, andgit -chook environments. It fails without the fix.