From 2776d1694dac6ebe2c95282ae4c90a45b147e212 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 13:06:55 +0100 Subject: [PATCH] Kill the surviving mutants of repos.py and url_beside --- bin/do_epic/repos.py | 6 +++--- bin/do_epic/test_repos.py | 10 +++++----- bin/forge/commands.py | 9 ++++----- bin/forge/test_forge.py | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bin/do_epic/repos.py b/bin/do_epic/repos.py index 4defb7a6..dc7ac8d8 100644 --- a/bin/do_epic/repos.py +++ b/bin/do_epic/repos.py @@ -66,7 +66,7 @@ def place_of(name: str, others: list[pathlib.Path], git: Git) -> str | Failure: """The address of the repo called name beside the others: all of them on one host and owner. An Unsure otherwise.""" if not others: return Unsure(f"{name} is missing and no other repo of the epic shows what host to clone it from. Where does it live?") - urls: dict[str, pathlib.Path] = {} + urls = set() for other in others: origin = git("remote", "get-url", "origin", cwd=str(other)) if isinstance(origin, Failure): @@ -74,9 +74,9 @@ def place_of(name: str, others: list[pathlib.Path], git: Git) -> str | Failure: beside = url_beside(origin.strip(), name) if beside is None: return Unsure(f"{other} has an origin, {origin.strip()}, with no place to put another repo in. Where does {name} live?") - urls[beside] = other + urls.add(beside) if len(urls) > 1: - return Unsure(f"The epic's other repos sit in more than one place, so {name} could be at {' or '.join(urls)}. Which holds it?") + return Unsure(f"The epic's other repos sit in more than one place, so {name} could be at {' or '.join(sorted(urls))}. Which holds it?") url = next(iter(urls)) if not re.fullmatch(CLONE_ADDRESS, url): return Unsure(f"{url} is not an https, ssh or scp-style address. Where does {name} live?") diff --git a/bin/do_epic/test_repos.py b/bin/do_epic/test_repos.py index fdc5003e..4e74e038 100644 --- a/bin/do_epic/test_repos.py +++ b/bin/do_epic/test_repos.py @@ -35,7 +35,7 @@ class LocateTest(unittest.TestCase): self.addCleanup(made.cleanup) self.home = pathlib.Path(made.name).resolve() self.projects = self.home / ".claude-projects" - self.config = DoEpicConfig(self.projects / "do-epic", "https://acme.atlassian.net", self.home / "jira.env", self.home / "code", "English", "claude-opus-5-5", "rule") + self.config = DoEpicConfig(self.projects / "do-epic", "https://acme.atlassian.net", self.home / "jira.env", self.home / "clones", "English", "claude-opus-5-5", "rule") self.billing, self.payments = self.home / "elsewhere" / "billing", self.home / "elsewhere" / "payments" self.origins: dict[str, str | Failure] = {str(self.billing): "git@github.com:acme/billing.git", str(self.payments): "git@github.com:acme/payments"} @@ -69,9 +69,9 @@ class LocateTest(unittest.TestCase): def test_clones_into_the_clone_folder_and_asks_for_a_config_where_none_names_the_repo(self) -> None: git = FakeGit(self.origins) asked = self.unsure(git) - self.assertEqual(git.cloned, [("git@github.com:acme/ledger", str(self.home / "code" / "ledger"))]) - self.assertIn(f"{self.projects}//config.toml", asked) - self.assertIn(f"checkout = \"{self.home / 'code' / 'ledger'}\"", asked) + clone = self.home / "clones" / "ledger" + self.assertEqual(git.cloned, [("git@github.com:acme/ledger", str(clone))]) + self.assertEqual(asked, f"{clone} was cloned, but no project config names it. Write {self.projects}//config.toml with `checkout = \"{clone}\"`, as `project-config --help` shows, and run do-epic again.") self.assertEqual(self.unsure(git), asked.replace("was cloned", "holds the repo"), "the second ask finds the clone and clones nothing") self.assertEqual(len(git.cloned), 1) @@ -80,7 +80,7 @@ class LocateTest(unittest.TestCase): self.origins[str(self.payments)] = "git@gitea.larvit.se:acme/payments" git = FakeGit(self.origins) asked = self.unsure(git) - self.assertIn("git@github.com:acme/ledger or git@gitea.larvit.se:acme/ledger", asked) + self.assertIn("git@gitea.larvit.se:acme/ledger or git@github.com:acme/ledger", asked) self.assertEqual(git.cloned, []) def test_asks_where_the_other_repos_differ_only_by_owner(self) -> None: diff --git a/bin/forge/commands.py b/bin/forge/commands.py index 75430ffc..ee92fbcf 100644 --- a/bin/forge/commands.py +++ b/bin/forge/commands.py @@ -18,11 +18,10 @@ def forge_of(origin_url: str) -> Forge: def url_beside(origin_url: str, name: str) -> str | None: - """The origin URL of the repo called name in the same place, host and owner, as origin_url's repo; None where origin_url has no place, such as a bare name. A trailing `.git` is dropped, since gh and tea clone without it.""" - trimmed = origin_url.rstrip("/").removesuffix(".git") - place = re.fullmatch(r"(.+[/:])[^/:]+", trimmed) - # A scheme's own `//` or `:` leaves no repo to put a name beside. - return place.group(1) + name if place and not place.group(1).endswith("//") and not re.fullmatch(r"\w+:", place.group(1)) else None + """The origin URL of the repo called name in the same place, host and owner, as origin_url's repo; None where origin_url has no place, such as a bare name. The URL has no `.git`, since gh and tea clone without it.""" + place = re.fullmatch(r"(.+[/:])[^/:]+", origin_url.rstrip("/")) + # A scheme's own `//` leaves no repo to put a name beside. + return place.group(1) + name if place and not place.group(1).endswith("//") else None def runner(cwd: str) -> Run: diff --git a/bin/forge/test_forge.py b/bin/forge/test_forge.py index c7b4380e..fcc8ca70 100644 --- a/bin/forge/test_forge.py +++ b/bin/forge/test_forge.py @@ -21,6 +21,7 @@ class UrlBeside(unittest.TestCase): self.assertEqual(url_beside("git@github.com:acme/billing.git", "ledger"), "git@github.com:acme/ledger") self.assertEqual(url_beside("https://gitea.larvit.se/acme/billing", "ledger"), "https://gitea.larvit.se/acme/ledger") self.assertEqual(url_beside("https://gitea.larvit.se/acme/billing.git/", "ledger"), "https://gitea.larvit.se/acme/ledger") + self.assertEqual(url_beside("gitea:billing", "ledger"), "gitea:ledger", "a host with no owner") def test_names_none_where_the_origin_has_no_place_to_put_a_repo_in(self): self.assertIsNone(url_beside("billing", "ledger"))