Skip to content

Audit cleanGitRepoEnv handling of Git config selector environment #771

@wesm

Description

@wesm

Problem

cleanGitRepoEnv was added to isolate Git ref resolution from repo-scoped environment leakage such as GIT_DIR, GIT_WORK_TREE, alternate object/index paths, namespace, prefix, quarantine state, and inline GIT_CONFIG_COUNT config injected by surrounding processes.

A review on the subagent/panel branch raised a plausible edge case: the current sanitizer also removes GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM. CI or containerized environments may intentionally set those variables for controlled Git configuration, for example safe.directory or system/global config isolation.

Why this needs a focused follow-up

This code is delicate because it sits between daemon/CI/test execution and Git process environment inheritance. The original isolation was intentional and should not be weakened casually. The right fix is to audit which environment variables are repository-scoped versus configuration-selector variables, then add focused tests for both cases.

Suggested investigation

  • Confirm which variables must be stripped to prevent stale repository context from affecting ResolveSHA.
  • Decide whether GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM should be preserved, stripped, or handled only under specific test/CI conditions.
  • Add regression tests covering:
    • stale GIT_DIR / GIT_WORK_TREE cannot redirect ref resolution;
    • config selector variables do not break intended controlled Git config, if preserved;
    • inline GIT_CONFIG_COUNT config remains stripped if it can override command behavior unexpectedly.

Context

The speculative branch-local fix was reverted from feat/proper-subagent-reviews; this should be addressed in a separate PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions