From f86349ca92fe75c354b7018daea169b991bdd679 Mon Sep 17 00:00:00 2001 From: codex Date: Thu, 28 May 2026 19:50:50 -0400 Subject: [PATCH] fix(git): rewrite logical ip upstream aliases --- bot_bottle/git_gate.py | 12 +++++++++++- bot_bottle/manifest.py | 2 ++ tests/unit/test_manifest_git.py | 1 + tests/unit/test_provision_git.py | 24 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/bot_bottle/git_gate.py b/bot_bottle/git_gate.py index 4fc7bfc..09a84dc 100644 --- a/bot_bottle/git_gate.py +++ b/bot_bottle/git_gate.py @@ -166,6 +166,17 @@ def git_gate_render_gitconfig( for entry in entries: out.append(f'[url "git://{gate_host}/{entry.Name}.git"]\n') out.append(f"\tinsteadOf = {entry.Upstream}\n") + if entry.RemoteKey and entry.RemoteKey != entry.UpstreamHost: + port = ( + f":{entry.UpstreamPort}" + if entry.UpstreamPort and entry.UpstreamPort != "22" + else "" + ) + alias = ( + f"ssh://{entry.UpstreamUser}@{entry.RemoteKey}{port}/" + f"{entry.UpstreamPath}" + ) + out.append(f"\tinsteadOf = {alias}\n") return "".join(out) @@ -404,4 +415,3 @@ class GitGate(ABC): access_hook_script=access_hook, upstreams=upstreams, ) - diff --git a/bot_bottle/manifest.py b/bot_bottle/manifest.py index e856a3a..fb5d776 100644 --- a/bot_bottle/manifest.py +++ b/bot_bottle/manifest.py @@ -85,6 +85,7 @@ class GitEntry: IdentityFile: str KnownHostKey: str = "" ExtraHosts: Mapping[str, str] = field(default_factory=_empty_str_dict) + RemoteKey: str = "" UpstreamUser: str = "" UpstreamHost: str = "" UpstreamPort: str = "" @@ -158,6 +159,7 @@ class GitEntry: IdentityFile=ident, KnownHostKey=khk, ExtraHosts=extra_hosts, + RemoteKey=host_key or host, UpstreamUser=user, UpstreamHost=host, UpstreamPort=port, diff --git a/tests/unit/test_manifest_git.py b/tests/unit/test_manifest_git.py index 90d22a2..a5b494b 100644 --- a/tests/unit/test_manifest_git.py +++ b/tests/unit/test_manifest_git.py @@ -217,6 +217,7 @@ class TestGitEntryCrossValidation(unittest.TestCase): "agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}}, }) e = m.bottles["dev"].git[0] + self.assertEqual("gitea.dideric.is", e.RemoteKey) self.assertEqual("100.78.141.42", e.UpstreamHost) self.assertEqual("30009", e.UpstreamPort) diff --git a/tests/unit/test_provision_git.py b/tests/unit/test_provision_git.py index c1f4e5f..0a891aa 100644 --- a/tests/unit/test_provision_git.py +++ b/tests/unit/test_provision_git.py @@ -10,6 +10,7 @@ from bot_bottle.git_gate import ( GIT_GATE_HOSTNAME, git_gate_render_gitconfig, ) +from bot_bottle.manifest import Manifest from tests.fixtures import fixture_minimal, fixture_with_git @@ -59,6 +60,29 @@ class TestGitGateGitconfigRender(unittest.TestCase): '[url "git://192.168.20.2:9418/bot-bottle.git"]', out, ) + def test_ip_upstream_also_rewrites_logical_remote_key(self): + m = Manifest.from_json_obj({ + "bottles": {"dev": {"git": {"remotes": { + "gitea.dideric.is": { + "Name": "bot-bottle", + "Upstream": "ssh://git@100.78.141.42:30009/didericis/bot-bottle.git", + "IdentityFile": "/dev/null", + }, + }}}}, + "agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}}, + }) + out = git_gate_render_gitconfig(m.bottles["dev"].git, GIT_GATE_HOSTNAME) + self.assertIn( + "\tinsteadOf = " + "ssh://git@100.78.141.42:30009/didericis/bot-bottle.git", + out, + ) + self.assertIn( + "\tinsteadOf = " + "ssh://git@gitea.dideric.is:30009/didericis/bot-bottle.git", + out, + ) + if __name__ == "__main__": unittest.main()