Skip to content

Establish GitContext dataclass for injectable git context#415

Merged
tschm merged 3 commits intomainfrom
copilot/establish-gitcontext-dataclass
Mar 8, 2026
Merged

Establish GitContext dataclass for injectable git context#415
tschm merged 3 commits intomainfrom
copilot/establish-gitcontext-dataclass

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 8, 2026

_get_diff was the only git-invoking function in _sync_helpers.py that resolved its own executable via get_git_executable() internally, making binary injection in tests impossible and breaking consistency with every other git-calling function in the module.

Changes

  • New GitContext dataclass (rhiza.models._git_utils) — bundles executable: str and env: dict[str, str]; exposes a GitContext.default() classmethod that mirrors the setup previously scattered across callers
  • Exported from rhiza.models — available as a first-class public API symbol
  • _get_diff now accepts git_ctx: GitContext — no longer resolves the binary itself; consistent with all other helpers in the module
  • _sync_diff propagates git_ctx: GitContext — threading the context down to _get_diff
  • _merge_with_base — constructs a GitContext inline from its existing git_executable/git_env params; no signature change required
  • sync.py — passes GitContext to _sync_diff
# Before — not injectable, inconsistent with peer functions
def _get_diff(repo0: Path, repo1: Path) -> str:
    git = get_git_executable()  # resolved internally
    ...

# After — explicit context, injectable in tests
def _get_diff(repo0: Path, repo1: Path, git_ctx: GitContext) -> str:
    ...subprocess.run([git_ctx.executable, ...], env=git_ctx.env, ...)

# Tests can now inject a custom binary without patching globals
ctx = GitContext(executable="/usr/bin/fake-git", env={})
diff = _get_diff(base, upstream, ctx)

Tests

  • TestGitContext added to test_subprocess_utils.py covering direct construction, default env values, and default() classmethod behaviour
  • All 16 _get_diff and _sync_diff call sites in test_sync.py updated to pass an explicit GitContext
Original prompt

This section details on the original issue you should resolve

<issue_title>Establish a GitContext Dataclass</issue_title>
<issue_description>_get_diff was the only git-invoking function in _sync_helpers.py that resolved its own executable internally via get_git_executable(), making it impossible to inject a different binary in tests and breaking consistency with every other git-calling function in the module.
GitContext could help here</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@tschm tschm marked this pull request as ready for review March 8, 2026 10:05
Co-authored-by: tschm <2046079+tschm@users.noreply.github.com>
Copilot AI changed the title [WIP] Establish GitContext dataclass for consistent git invocation Establish GitContext dataclass for injectable git context Mar 8, 2026
Copilot finished work on behalf of tschm March 8, 2026 10:09
@tschm tschm merged commit b5517b6 into main Mar 8, 2026
15 checks passed
@tschm tschm deleted the copilot/establish-gitcontext-dataclass branch March 8, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Establish a GitContext Dataclass

2 participants