fix(git-guards): mock _is_on_main_branch() via GIT_GUARD_BRANCH_OVERRIDE#263
fix(git-guards): mock _is_on_main_branch() via GIT_GUARD_BRANCH_OVERRIDE#263JacobPEvans wants to merge 4 commits intomainfrom
Conversation
… [issue-solver-2026-04-28]
…ch (#261) [issue-solver-2026-04-28]
There was a problem hiding this comment.
Code Review
This pull request introduces a GIT_GUARD_BRANCH_OVERRIDE environment variable to the _is_on_main_branch function, allowing the branch status to be mocked. The test suite has been updated to use this override, ensuring consistent test results regardless of the actual git environment. I have no feedback to provide.
There was a problem hiding this comment.
Pull request overview
This PR addresses CI failures in git-guards/scripts/test_permission_guard.py when tests run on the main branch by introducing an environment-variable override to make _is_on_main_branch() deterministic in CI.
Changes:
- Added
GIT_GUARD_BRANCH_OVERRIDEhandling in_is_on_main_branch()to bypass git-based branch detection when set. - Updated three permission-guard tests to set/unset the override so they validate hook-bypass/force-push logic rather than the main-branch block.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| git-guards/scripts/git-permission-guard.py | Adds env-var branch override path to _is_on_main_branch() to avoid CI branch-state coupling. |
| git-guards/scripts/test_permission_guard.py | Sets GIT_GUARD_BRANCH_OVERRIDE=feature around three cases that otherwise get blocked on main. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…H_OVERRIDE
- Add branch_override() context manager to preserve/restore any
pre-existing GIT_GUARD_BRANCH_OVERRIDE value around each test call
- Replace three raw set/pop blocks with 'with branch_override("feature"):'
- Add docstring note to _is_on_main_branch() documenting the override
path and its CI/test-only intent
* chore(git-standards): forbid emoji in commits and PR titles Adds an explicit "Commit & PR Title Style" section to the pr-standards skill (loaded on demand whenever an agent drafts a PR), and a one-line cross-reference bullet in git-workflow-standards. Companion to the soul.md flip in ai-assistant-instructions. Together these eliminate the gap that caused recent automated AI-fix PRs (#263, #257) to land with `🤖` prefixes — soul.md was endorsing gitmoji and neither plugin skill said otherwise. Applies to human, AI-assisted, and bot-authored PRs alike. Conventional- commit prefixes carry the signal. (claude) * fix(git-standards): clarify emoji-ban scope and conventional-commit phrasing Addresses copilot review feedback (threads VOoy, VOpG, VOpT) on PR #266. Changes: - Rename section header from "Commit & PR Title Style" to "Commit, PR Title & PR Description Style" (header now matches body scope) - Split rule into two parts: emoji ban (commits + titles + descriptions + release notes) and conventional-commit prefix requirement (commit subjects + PR titles only) - Replace ambiguous "Use conventional-commit prefixes only" with "are required at the start of commit subjects and PR titles only" — the original "only" was meant to scope where prefixes apply, but read as if the prefix should be the entire message - Add release notes to the ban for parity with the soul.md update in ai-assistant-instructions PR #604 (claude)
Replace the hand-rolled branch_override @contextmanager with a thin wrapper around unittest.mock.patch.dict — stdlib already provides the exact save-and-restore semantics (including key-deletion when previously unset). (claude)
Closes #261
Summary
Three tests in
git-guards/scripts/test_permission_guard.pyfail on the main branch because_is_on_main_branch()returns true (GitHub Actions CI has a detached HEAD), causing the main-branch guard to block test logic before hook-bypass detection can run. This PR adds an environment variable escape hatch so tests can override branch detection without touching git.Changes
GIT_GUARD_BRANCH_OVERRIDEenv-var check at the top of_is_on_main_branch(). When set, returns(override == "main")directly without callinggit branch --show-current.branch_override()context manager (using@contextmanagerfrom contextlib) that safely saves/restores the env-var. Tests now run withGIT_GUARD_BRANCH_OVERRIDE=featureto simulate non-main branch.Test Plan
_is_on_main_branch()behavior when env-var is unset (normal git call path)Generated by Issue Solver — prompt source: https://github.com/JacobPEvans/claude-code-routines/blob/main/routines/issue-solver.prompt.md