[brencher] Add per-remote branch prefix filtering for multi-remote GitClone #30

Open
opened 2026-08-30 22:26:03 +02:00 by hermes · 0 comments
Contributor

Add per-remote branch prefix filtering for multi-remote GitClone

Context

GitClone.branchNamePrefix is silently ignored when constructed with the explicit remotes=[...] form (verified in backend/steps/git.py:106):

if remote_name == "origin" and self.branchNamePrefix != "":
    config.set_value('remote "origin"', "fetch",
        f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")

The prefix only fires when a remote is named "origin". The remotes= form passes names through verbatim, so configs like:

clone = GitClone(remotes=[
    {"name": "github",       "url": "..."},
    {"name": "gitea_hermes", "url": "..."},
    {"name": "gitea_admin",  "url": "..."},
], branchNamePrefix="ansible")

…set the prefix on the clone but never apply it. All remotes fetch their full refset.

This blocks PR #28 (hermes.py migration) and any future multi-remote config that wants to keep its branch list scoped.

Proposed API

Extend each remote entry to optionally carry a prefix:

clone = GitClone(remotes=[
    {"name": "github",       "url": "...", "prefix": "ansible"},
    {"name": "gitea_hermes", "url": "...", "prefix": "ansible"},
    {"name": "gitea_admin",  "url": "...", "prefix": "ansible"},
])

Behavior:

  • If prefix is set on a remote, the fetch refspec for that remote becomes +refs/heads/<prefix>/*:refs/remotes/<name>/<prefix>/*.
  • If prefix is absent (current behavior), the default refspec +refs/heads/*:refs/remotes/<name>/* is used.
  • Top-level branchNamePrefix continues to apply to a remote named "origin" for backwards compatibility with url= shorthand.

Migration path

After this change:

  • hermes_infra.py after PR #8 — already drops branchNamePrefix, no change needed.
  • All migration PRs (#26 gmail_mcp, #28 hermes, future #19 gitea.py) — add "prefix": "ansible" (or "immoscout") to each remote entry.
  • Existing url= configs (single-remote, with branchNamePrefix) — keep working unchanged.

Acceptance criteria

  1. GitClone(remotes=[{"name": "x", "url": "...", "prefix": "ansible"}]) fetches only ansible/* branches from remote x.
  2. GitClone(remotes=[{"name": "x", "url": "..."}]) (no prefix) fetches all branches — backwards-compatible.
  3. GitClone(url="...", branchNamePrefix="ansible") (single-remote shorthand) still applies prefix to the implicit origin remote.
  4. Mixed: some remotes with prefix, some without — each behaves independently.
  5. Test coverage: tests/test_git_integration.py gets a new test case exercising the per-remote prefix.
  6. PR #28 can be re-opened with the new contract (replace branchNamePrefix="ansible" with "prefix": "ansible" per remote).

Out of scope

  • Changing the branchNamePrefix semantics globally (e.g. applying to all remotes by default).
  • Changing git_clone URL conventions.

Implementation hint

The change is localized to backend/steps/git.py:106-110. The refspec building loop needs to consider per-remote prefix. The dict normalization (__init__) should validate that prefix is a string when present.

Refs PR #28
Blocks #18 (parent migration ticket)

## Add per-remote branch prefix filtering for multi-remote `GitClone` ### Context `GitClone.branchNamePrefix` is silently ignored when constructed with the explicit `remotes=[...]` form (verified in `backend/steps/git.py:106`): ```python if remote_name == "origin" and self.branchNamePrefix != "": config.set_value('remote "origin"', "fetch", f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*") ``` The prefix only fires when a remote is named `"origin"`. The `remotes=` form passes names through verbatim, so configs like: ```python clone = GitClone(remotes=[ {"name": "github", "url": "..."}, {"name": "gitea_hermes", "url": "..."}, {"name": "gitea_admin", "url": "..."}, ], branchNamePrefix="ansible") ``` …set the prefix on the clone but **never apply it**. All remotes fetch their full refset. This blocks PR #28 (hermes.py migration) and any future multi-remote config that wants to keep its branch list scoped. ### Proposed API Extend each remote entry to optionally carry a `prefix`: ```python clone = GitClone(remotes=[ {"name": "github", "url": "...", "prefix": "ansible"}, {"name": "gitea_hermes", "url": "...", "prefix": "ansible"}, {"name": "gitea_admin", "url": "...", "prefix": "ansible"}, ]) ``` Behavior: - If `prefix` is set on a remote, the fetch refspec for that remote becomes `+refs/heads/<prefix>/*:refs/remotes/<name>/<prefix>/*`. - If `prefix` is absent (current behavior), the default refspec `+refs/heads/*:refs/remotes/<name>/*` is used. - Top-level `branchNamePrefix` continues to apply to a remote named `"origin"` for backwards compatibility with `url=` shorthand. ### Migration path After this change: - `hermes_infra.py` after PR #8 — already drops `branchNamePrefix`, no change needed. - All migration PRs (#26 gmail_mcp, #28 hermes, future #19 gitea.py) — add `"prefix": "ansible"` (or `"immoscout"`) to each remote entry. - Existing `url=` configs (single-remote, with `branchNamePrefix`) — keep working unchanged. ### Acceptance criteria 1. `GitClone(remotes=[{"name": "x", "url": "...", "prefix": "ansible"}])` fetches only `ansible/*` branches from remote `x`. 2. `GitClone(remotes=[{"name": "x", "url": "..."}])` (no prefix) fetches all branches — backwards-compatible. 3. `GitClone(url="...", branchNamePrefix="ansible")` (single-remote shorthand) still applies prefix to the implicit `origin` remote. 4. Mixed: some remotes with prefix, some without — each behaves independently. 5. Test coverage: `tests/test_git_integration.py` gets a new test case exercising the per-remote prefix. 6. PR #28 can be re-opened with the new contract (replace `branchNamePrefix="ansible"` with `"prefix": "ansible"` per remote). ### Out of scope - Changing the `branchNamePrefix` semantics globally (e.g. applying to all remotes by default). - Changing `git_clone` URL conventions. ### Implementation hint The change is localized to `backend/steps/git.py:106-110`. The refspec building loop needs to consider per-remote `prefix`. The dict normalization (`__init__`) should validate that `prefix` is a string when present. Refs PR #28 Blocks #18 (parent migration ticket)
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/brencher#30