From 624729d7c798db2926d9e575624c9169ea8fc409 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 25 Nov 2026 00:18:44 +0000 Subject: [PATCH] fix(kvb-git-hotfix): let a local checkout as origin stand for its own upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A hotfix added from a --shared funnel clone whose origin insteadOf rewrites to the local core checkout recorded that path as its origin, so update --repo refused it as another repository. An origin that is the top level of a checkout with an origin of its own now resolves to that origin, up to HOPS times and never in a circle, both for the live repository and for rows recorded with the local path. 🎯 Fix: 93 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 89 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- skills/kvb-git-hotfix/scripts/hotfix.py | 28 ++++++++++++++++--- tests/test_hotfix.py | 36 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/skills/kvb-git-hotfix/scripts/hotfix.py b/skills/kvb-git-hotfix/scripts/hotfix.py index a59ef60..63a3d82 100755 --- a/skills/kvb-git-hotfix/scripts/hotfix.py +++ b/skills/kvb-git-hotfix/scripts/hotfix.py @@ -73,7 +73,11 @@ Args: `git ls-remote --get-url origin`, so insteadOf rules apply, and compare without scheme, user, port, `.git` and trailing slash; a local path resolves against the worktree's top level, and the path on a - case-insensitive host of CASELESS compares in lowercase. A merged hotfix + case-insensitive host of CASELESS compares in lowercase. A local path + that is the top level of a checkout with an origin of its own stands for + that origin, followed up to HOPS times and never in a circle, so a + funnel clone of a local checkout and a recorded local path both match + the checkout's upstream. A merged hotfix missing from HEAD counts only when its sha is on origin/; when it is not, one fetch decides. Every fetch (sync, pending, void, and add or update with --status merged) runs with GIT_TERMINAL_PROMPT=0 and is @@ -146,6 +150,7 @@ ORIGIN_HEAD = "refs/remotes/origin/HEAD" GIT = ("git", "-c", "maintenance.auto=false") FETCH = ("fetch", "--quiet", "--no-auto-maintenance", "origin") FETCH_SECONDS = 120 +HOPS = 4 CREATED_WITH = "Created-with: https://s.veen.world/skills" PKGMGR_FLOW = ("pkgmgr", "worktree", "flow") FLOW_FILE = ("pkgmgr", "flow.yml") @@ -266,12 +271,27 @@ def normalized(url: str, top: str) -> str: return os.path.realpath(os.path.join(top, path)).removesuffix(".git").rstrip("/") -def origin_url(where: str) -> str: +def origin_url(where: str, seen: frozenset[str] = frozenset()) -> str: if not git(where, "config", "--get", "remote.origin.url").stdout.strip(): return "" url = git(where, "ls-remote", "--get-url", "origin").stdout top = git(where, "rev-parse", "--show-toplevel") - return normalized(url, top.stdout.strip() if top.returncode == 0 else where) + return upstream(normalized(url, top.stdout.strip() if top.returncode == 0 else where), + seen | {os.path.realpath(where)}) + + +def upstream(origin: str, seen: frozenset[str] = frozenset()) -> str: + """Returns: + origin, or when origin is the top level of a local checkout with an + origin of its own, that checkout's origin, followed up to HOPS times + and never back into a path in seen. + """ + if not origin.startswith("/") or len(seen) > HOPS or origin in seen or not os.path.isdir(origin): + return origin + top = git(origin, "rev-parse", "--show-toplevel") + if top.returncode or os.path.realpath(top.stdout.strip()) != origin: + return origin + return origin_url(origin, seen) or origin def identity(where: str) -> tuple[str, str] | None: @@ -290,7 +310,7 @@ def same(one: tuple[str, str], other: tuple[str, str]) -> bool: def recorded(row: dict) -> tuple[str, str] | None: - common, origin = row.get("common_dir") or "", row.get("origin") or "" + common, origin = row.get("common_dir") or "", upstream(row.get("origin") or "") if not origin and not os.path.isdir(common): return None return common, origin diff --git a/tests/test_hotfix.py b/tests/test_hotfix.py index 00c30f3..6c5af75 100644 --- a/tests/test_hotfix.py +++ b/tests/test_hotfix.py @@ -693,6 +693,42 @@ class TestHotfix(unittest.TestCase): self.assertEqual(self.out("match", "--line", "github boom", "--repo", str(second)), [f"hotfix/gh\tstaged\tfix/gh\t{sha}\t-\tgithub.com/org/app"]) + def test_a_funnel_clone_of_a_local_checkout_belongs_to_the_checkouts_upstream(self): + funnel = self.base / "funnel" + self.git(self.base, "clone", "-q", "--shared", str(self.seed), str(funnel)) + self.git(funnel, "config", f"url.{self.seed}.insteadOf", "gh:org/app") + self.git(funnel, "remote", "set-url", "origin", "gh:org/app") + sha = self.commit(funnel, "funnel.txt", "funnel\n", "fix funnel") + self.out("add", "funnel", *self.flags({"--repo": str(funnel), "--branch": "fix/funnel", "--sha": sha, + "--signature": "funnel boom", "--status": "pr", "--pr": "21"})) + upstream = str(self.base / "origin") + self.assertEqual(self.rows()["hotfix/funnel"]["origin"], upstream) + self.assertEqual(self.out("match", "--line", "funnel boom", "--repo", str(self.seed)), + [f"hotfix/funnel\tpr\tfix/funnel\t{sha}\t#21\t{upstream}"]) + rows = self.rows() + rows["hotfix/funnel"]["origin"] = str(self.seed) + self.write_rows(rows) + self.git(self.seed, "fetch", "-q", str(funnel), "HEAD") + self.git(self.seed, "push", "-q", "origin", "FETCH_HEAD:refs/heads/main") + self.out("update", "funnel", "--status", "merged", "--sha", sha, "--repo", str(self.seed)) + row = self.rows()["hotfix/funnel"] + self.assertEqual((row["stage"], row["origin"], row["common_dir"]), ("merged", upstream, str(self.seed / ".git"))) + + def test_only_the_top_level_of_a_checkout_is_followed_and_never_in_a_circle(self): + one, two = self.base / "c1", self.base / "c2" + for repo, other in ((one, two), (two, one)): + repo.mkdir() + self.git(repo, "init", "-q", "-b", "main") + self.git(repo, "remote", "add", "origin", str(other)) + inner = self.seed / "inner" + inner.mkdir() + hotfix = load_hotfix() + with mock.patch.dict(os.environ, self.env): + self.assertEqual(hotfix.origin_url(str(one)), str(one)) + self.assertEqual(hotfix.upstream(str(inner)), str(inner)) + self.assertEqual(hotfix.upstream(str(self.seed)), str(self.base / "origin")) + self.assertEqual(hotfix.upstream("github.com/org/app"), "github.com/org/app") + def test_pending_filters_by_targets_as_void_does(self): lint = f"open, not merged\thotfix/lint\tpr\tfix/lint\t{self.lint}\t#13" result = self.hotfix("pending", "--repo", str(self.work), "--target", "test-lint")