Ship the two maintainer workflow helpers as installable Python CLIs so
any fork-based OSS project can reuse them without vendoring shell
scripts:
* git-setup-remotes configures origin/fork/main-tracking/pushDefault
for a fork-based clone. URLs are parameterized (--canonical / --fork
or CANONICAL_URL / FORK_URL) so the same binary bootstraps any
maintainer's repo. Idempotent.
* git-sign-push GPG-signs every unpushed commit on the current branch
and pushes, resolving the target remote from remote.pushDefault
(falling back to origin) for branches without upstream.
Both refuse to run when CLAUDE_CODE/CLAUDECODE is set, since the Claude
sandbox blocks .git/config writes and access to ~/.gnupg: failing fast
beats failing late.
Other additions:
* Makefile: install / install-dev / test / lint / clean targets.
* .github/workflows/test.yml: pytest + ruff matrix for py 3.10/11/12.
* MIRRORS: github, git.veen.world:2201, code.infinito.nexus:2201, pypi.
* LICENSE switched to MIT; README records the extraction origin
(s.infinito.nexus/code) and adds author + license sections.
* Tests cover sandbox-refusal guards and the fork-URL resolution
preference order (CLI arg > env var > existing fork remote > origin
when not canonical).
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""Fork URL resolution logic for `git-setup-remotes`."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from git_maintainer_tools import setup_remotes
|
|
|
|
|
|
def test_cli_arg_wins(monkeypatch):
|
|
monkeypatch.delenv("FORK_URL", raising=False)
|
|
# Make helpers fail fast so we know we did not fall through.
|
|
monkeypatch.setattr(setup_remotes.g, "remote_url", lambda _: None)
|
|
assert (
|
|
setup_remotes.resolve_fork_url("git@host:x/y.git", "git@host:canon/z.git")
|
|
== "git@host:x/y.git"
|
|
)
|
|
|
|
|
|
def test_env_var_used_when_arg_missing(monkeypatch):
|
|
monkeypatch.setenv("FORK_URL", "git@host:env/y.git")
|
|
monkeypatch.setattr(setup_remotes.g, "remote_url", lambda _: None)
|
|
assert (
|
|
setup_remotes.resolve_fork_url(None, "git@host:canon/z.git")
|
|
== "git@host:env/y.git"
|
|
)
|
|
|
|
|
|
def test_existing_fork_remote_used(monkeypatch):
|
|
monkeypatch.delenv("FORK_URL", raising=False)
|
|
|
|
def fake(name):
|
|
return "git@host:existing/fork.git" if name == "fork" else None
|
|
|
|
monkeypatch.setattr(setup_remotes.g, "remote_url", fake)
|
|
assert (
|
|
setup_remotes.resolve_fork_url(None, "git@host:canon/z.git")
|
|
== "git@host:existing/fork.git"
|
|
)
|
|
|
|
|
|
def test_origin_reused_when_not_canonical(monkeypatch):
|
|
monkeypatch.delenv("FORK_URL", raising=False)
|
|
|
|
def fake(name):
|
|
return {"origin": "git@host:user/fork.git"}.get(name)
|
|
|
|
monkeypatch.setattr(setup_remotes.g, "remote_url", fake)
|
|
assert (
|
|
setup_remotes.resolve_fork_url(None, "git@host:canon/z.git")
|
|
== "git@host:user/fork.git"
|
|
)
|
|
|
|
|
|
def test_origin_ignored_when_canonical(monkeypatch):
|
|
monkeypatch.delenv("FORK_URL", raising=False)
|
|
canonical = "git@host:canon/z.git"
|
|
|
|
def fake(name):
|
|
return {"origin": canonical}.get(name)
|
|
|
|
monkeypatch.setattr(setup_remotes.g, "remote_url", fake)
|
|
assert setup_remotes.resolve_fork_url(None, canonical) is None
|