fix: skip merged branches during git repository sync
Why
The recurring git_repositories_sync flow records each branch's commit via
CoreRepositoryUpdate. When a git branch still present on the remote maps to an
Infrahub branch that has already been merged (and is therefore read-only), the
mutation is rejected. That GraphQLError was isolated by neither the per-branch
handler nor any enclosing frame, so a single merged-but-undeleted branch aborted
the entire recurring flow every cron cycle — freezing sync for the affected
repository and every repository iterated after it until the branch was deleted.
Goal: a merged/read-only branch lingering on the remote no longer breaks sync.
Non-goals: no change to the server-side read-only guard (rejecting writes to a
merged branch is correct); no broader rework of the sync error-handling model.
Closes #9931
What changed
- Recurring git sync now skips branches whose Infrahub branch is in a terminal
status (merged / being deleted) instead of trying to record their commit —
so one merged branch can no longer stall the whole sync.
Implementation: collect_pending_imports filters both the new- and updated-branch
lists through a new _exclude_read_only_branches helper, which reads branch
statuses once via branch.all() and drops any whose mapped Infrahub branch is in
TERMINAL_BRANCH_STATUSES. No new per-branch queries; reuses the existing enum.
What stayed the same: the staging-import path is unaffected (the default branch is
never terminal). No schema, GraphQL, or SDK changes.
How to test
INFRAHUB_USE_TEST_CONTAINERS=true uv run pytest \
backend/tests/integration/git/test_sync_merged_branch.py -v
Without the fix the test errors with the GraphQLError from the issue; with it the
sync completes and the merged branch is skipped. Regression-checked against
backend/tests/component/git/test_sync_repository.py and backend/tests/unit/git/.
Impact & rollout
- Backward compatibility: no breaking changes; behavior-only fix.
- Config/env changes: none.
- Deployment notes: safe to deploy.
Checklist
- Tests added/updated
- Changelog entry added
- External docs updated — N/A (internal sync behavior)
- Internal .md docs reviewed — no update needed (
branch-status.mddocuments the read-only enforcement points; this fix is a consumer honoring them) - I have reviewed AI generated content
Summary by cubic
Skip branches mapped to merged/read-only Infrahub branches during recurring git repository sync so a lingering merged branch no longer halts the whole flow. Fixes #9931.
- Bug Fixes
- Filter
new_branchesandupdated_branchesvia_exclude_read_only_branchesusingTERMINAL_BRANCH_STATUSESto drop terminal (merged/deleting) branches. - Added integration test to confirm merged branches are skipped and sync completes.
- Stubbed
infrahub_sdk.branch.InfrahubBranchManager.allin component testconftestand applied across sync and lock-scope tests to avoid the dummy SDK KeyError.
- Filter