feat(git): per-remote branch prefix filtering for multi-remote GitClone #31

Merged
admin merged 2 commits from hermes/brencher:feat/per-remote-branch-prefix into main 2026-09-05 19:20:47 +02:00
Contributor

Summary

GitClone's top-level branchNamePrefix argument was silently ignored when constructed with the explicit remotes=[...] form (verified in backend/steps/git.py:106):

if remote_name == "origin" and self.branchNamePrefix != "":
    # apply refspec

The prefix only fires when a remote is named "origin". The remotes= form passes names through verbatim, so configs like the open PR #28 set the prefix but never apply it — all branches from all remotes are fetched.

This PR extends the API: each remote entry now optionally accepts a prefix field. When set, the fetch refspec for that remote becomes scoped to <prefix>/* branches. Backwards-compatible — remotes without prefix keep the existing behavior, and url= shorthand with branchNamePrefix still works.

API

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

Each remote is independent — some can have prefix, others not.

Changes

backend/steps/git.py

  • __init__ (remotes= branch): validate prefix (string if set, reject non-string with ValueError), persist into the normalized entry. Empty string / None → no prefix applied (existing behavior).
  • progress() fetch loop: replace the single if remote_name == "origin" check with per-entry logic. Effective prefix = entry["prefix"] or (self.branchNamePrefix if remote_name == "origin" else ""). Apply refspec per remote when effective prefix is non-empty.

tests/test_git_integration.py

3 new tests in TestGitIntegration:

  • test_git_clone_remotes_per_remote_prefix — both remotes prefixed; only ansible/* branches visible, master is filtered out.
  • test_git_clone_remotes_mixed_prefix — one remote prefixed, one not; each behaves independently.
  • test_git_clone_remotes_prefix_validation — prefix=123 / prefix=["ansible"] raise ValueError; prefix="" and missing-prefix are accepted.

Existing test_git_clone_named_remotes continues to pass (verified — no behavior change for unprefixed remotes).

Test results

29 passed in ~13s

(18 in test_git_integration.py, 11 in test_dummy.py/test_caching_step.py/test_cached_env.py.)

Migration path

After merge:

  • Open migration PRs (#26 gmail_mcp, #28 hermes, planned #19 gitea.py) — switch from branchNamePrefix="ansible" to "prefix": "ansible" on each remote.
  • hermes_infra.py after PR #8 already drops branchNamePrefix, no change needed.
  • Existing url= configs (immich, gmail_mcp-old, hermes-old, registry, gitea-old) — unaffected.

Unblocks

PR #28 — once this lands, hermes.py can drop the (currently misleading) top-level branchNamePrefix="ansible" and add "prefix": "ansible" per remote.

Refs #30
Blocks #28
Part of #18 (parent migration ticket)

## Summary `GitClone`'s top-level `branchNamePrefix` argument was silently ignored when constructed with the explicit `remotes=[...]` form (verified in `backend/steps/git.py:106`): ```python if remote_name == "origin" and self.branchNamePrefix != "": # apply refspec ``` The prefix only fires when a remote is named `"origin"`. The `remotes=` form passes names through verbatim, so configs like the open PR #28 set the prefix but never apply it — all branches from all remotes are fetched. This PR extends the API: each remote entry now optionally accepts a `prefix` field. When set, the fetch refspec for that remote becomes scoped to `<prefix>/*` branches. Backwards-compatible — remotes without `prefix` keep the existing behavior, and `url=` shorthand with `branchNamePrefix` still works. ## API ```python clone = GitClone(remotes=[ {"name": "github", "url": "...", "prefix": "ansible"}, {"name": "gitea_hermes", "url": "...", "prefix": "ansible"}, {"name": "gitea_admin", "url": "...", "prefix": "ansible"}, ]) ``` Each remote is independent — some can have `prefix`, others not. ## Changes ### `backend/steps/git.py` - `__init__` (`remotes=` branch): validate `prefix` (string if set, reject non-string with `ValueError`), persist into the normalized entry. Empty string / None → no prefix applied (existing behavior). - `progress()` fetch loop: replace the single `if remote_name == "origin"` check with per-entry logic. Effective prefix = `entry["prefix"] or (self.branchNamePrefix if remote_name == "origin" else "")`. Apply refspec per remote when effective prefix is non-empty. ### `tests/test_git_integration.py` 3 new tests in `TestGitIntegration`: - `test_git_clone_remotes_per_remote_prefix` — both remotes prefixed; only `ansible/*` branches visible, `master` is filtered out. - `test_git_clone_remotes_mixed_prefix` — one remote prefixed, one not; each behaves independently. - `test_git_clone_remotes_prefix_validation` — `prefix=123` / `prefix=["ansible"]` raise `ValueError`; `prefix=""` and missing-`prefix` are accepted. Existing `test_git_clone_named_remotes` continues to pass (verified — no behavior change for unprefixed remotes). ## Test results ``` 29 passed in ~13s ``` (18 in `test_git_integration.py`, 11 in `test_dummy.py`/`test_caching_step.py`/`test_cached_env.py`.) ## Migration path After merge: - Open migration PRs (#26 gmail_mcp, #28 hermes, planned #19 gitea.py) — switch from `branchNamePrefix="ansible"` to `"prefix": "ansible"` on each remote. - `hermes_infra.py` after PR #8 already drops `branchNamePrefix`, no change needed. - Existing `url=` configs (immich, gmail_mcp-old, hermes-old, registry, gitea-old) — unaffected. ## Unblocks PR #28 — once this lands, hermes.py can drop the (currently misleading) top-level `branchNamePrefix="ansible"` and add `"prefix": "ansible"` per remote. Refs #30 Blocks #28 Part of #18 (parent migration ticket)
hermes added 1 commit 2026-08-30 23:02:22 +02:00
feat(git): per-remote branch prefix filtering for multi-remote GitClone
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.12.3) (pull_request) Successful in 45s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.13) (pull_request) Successful in 40s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.14) (pull_request) Successful in 44s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.12.3) (pull_request) Successful in 37s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.13) (pull_request) Successful in 41s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.14) (pull_request) Successful in 39s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.12.3) (pull_request) Failing after 2m4s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.13) (pull_request) Failing after 2m15s
Python package / build (pip list, 3.12.3) (pull_request) Successful in 58s
Python package / build (pip list, 3.13) (pull_request) Successful in 42s
Python package / build (pip list, 3.14) (pull_request) Successful in 44s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.12.3) (pull_request) Successful in 39s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.13) (pull_request) Successful in 39s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.14) (pull_request) Successful in 42s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.14) (pull_request) Failing after 2m29s
95e60ed317
GitClone's branchNamePrefix argument was silently ignored when constructed
with the explicit remotes= form unless one of the remotes was named
'origin'. Multi-remote configs (introduced in #3) cannot use 'origin'
because that name is taken by the auto-generated shorthand.

Extend each remote entry to optionally carry a 'prefix' field. When set,
the fetch refspec for that remote becomes
  +refs/heads/<prefix>/*:refs/remotes/<name>/<prefix>/*
filtering branches at fetch time.

Backwards compatible: remotes without 'prefix' continue to fetch all
branches; url= shorthand with branchNamePrefix still applies the prefix
to the implicit 'origin' remote.

Closes #30
Blocks #28 (PR: hermes.py migration) — once merged, hermes.py can be
re-opened with 'prefix': 'ansible' per remote instead of the misleading
top-level branchNamePrefix.
admin added 1 commit 2026-08-30 23:05:14 +02:00
Merge branch 'main' into feat/per-remote-branch-prefix
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.12.3) (pull_request) Successful in 44s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.13) (pull_request) Successful in 42s
Python package / build (flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics, 3.14) (pull_request) Successful in 55s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.12.3) (pull_request) Successful in 1m4s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.13) (pull_request) Successful in 1m4s
Python package / build (flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics, 3.14) (pull_request) Successful in 1m14s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.12.3) (pull_request) Failing after 2m10s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.13) (pull_request) Failing after 2m4s
Python package / build (mypy --no-incremental --config-file mypy.ini backend tests, 3.14) (pull_request) Failing after 2m4s
Python package / build (pip list, 3.12.3) (pull_request) Successful in 43s
Python package / build (pip list, 3.13) (pull_request) Successful in 44s
Python package / build (pip list, 3.14) (pull_request) Successful in 45s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.12.3) (pull_request) Successful in 44s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.13) (pull_request) Successful in 42s
Python package / build (python -c "import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')", 3.14) (pull_request) Successful in 53s
bbd9515da9
admin merged commit 99f8b73654 into main 2026-09-05 19:20:47 +02:00
admin deleted branch feat/per-remote-branch-prefix 2026-09-05 19:20:48 +02:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/brencher#31