Skip to content

Clear Repository-Location Variables in Every Temporary-Repository Test Through One Helper #3324

Closed

Description

@ptr727

Defect

A test or self-test that builds a temporary repository with git -C <tmp> or cwd=<tmp> inherits any GIT_DIR, GIT_WORK_TREE, or GIT_INDEX_FILE in its environment. A git hook sets these, so a suite run from a hook writes its init, config, and commits into the hook's own repository instead of the temporary one.

#3323 fixes this inside the write guard's --selftest, which clears the repository-location variables once around every case. The guard installs as one standalone file, so it cannot share that primitive, and the other sites carry their own differing lists or none:

  • spec/audit.py _selftest: its temporary repositories (the deletion probe and the cases after it) run git init, git config user.email, git add, and git commit with cwd= and no clearing at all. The file has no GIT_DIR handling anywhere, so this is the destructive case.
  • host-setup/agent-safety/claude/test_install.py, TestAliasReadThroughLinkedWorktreeGitfile: drops GIT_DIR, GIT_WORK_TREE, GIT_COMMON_DIR, and GIT_OBJECT_DIRECTORY, but not GIT_INDEX_FILE, which a pre-commit hook sets, before its commit and worktree add.
  • tests/test_pr_review.py _DISCOVERY_VARS / _clean_env, tests/test_pre_commit_hook.py (strips by the GIT_ prefix), and scripts/local_review.py INHERITED_REDIRECTS (three names): each a different variant of the same list.

Reproduction

Construct a scratch repository, point GIT_DIR at its .git, and run python3 spec/audit.py --selftest. The scratch repository's config and history change.

Expected

One shared helper for the scripts and tests that can import it, holding the full repository-location list, with every site above moved onto it. spec/audit.py's self-test comes first, since it clears nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscriptA defect in hub tooling

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions