Cut a patch release of only the commits named with deploy-release --cut-patch

This commit is contained in:
Lilleman
2026-11-24 14:09:56 +01:00
parent 80de753b9e
commit 9c2587b5ca
6 changed files with 389 additions and 24 deletions
+124 -1
View File
@@ -248,7 +248,7 @@ class Cut(unittest.TestCase):
self.git(self.temp, "init", "-q", "--bare", "-b", "main", str(self.origin))
self.clone = self.temp / "claude-config"
self.git(self.temp, "clone", "-q", str(self.origin), str(self.clone))
self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0")}, "Start")
self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0"), "tool.txt": "broken\n", "ci.sh": "exit 0\n"}, "Start")
self.git(self.clone, "tag", "-a", "v0.1.0", "-m", "Cut release 0.1.0")
self.commit({"CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0")}, "Ship item 1")
self.git(self.clone, "commit", "-q", "--allow-empty", "-m", "Release review of 0.2.0")
@@ -469,6 +469,129 @@ class Cut(unittest.TestCase):
self.assertEqual(self.cut().returncode, 1, "0.2.0 is cut, so a second run refuses")
self.assertEqual(self.git(self.clone, "tag", "-l", "v0.2.0", "v9.9.9").split(), ["v0.2.0", "v9.9.9"])
def plan_patch(self, fix: dict[str, str] | None = None) -> str:
"""On top of setUp's main: a feature no patch may ship, item 3 filed under 0.1.1, then the commit that fixes tool.txt and finishes item 3, pushed. The revision range that names only the fix."""
self.commit({"feature.txt": "new\n"}, "Add a feature")
self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=3, release="0.1.1")}, "File item 3")
base = self.git(self.clone, "rev-parse", "HEAD").strip()
self.commit({"tool.txt": "fixed\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0"), "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n", **(fix or {})}, "Fix item 3")
head = self.git(self.clone, "rev-parse", "HEAD").strip()
self.git(self.clone, "push", "-q", "origin", "main")
return f"{base}..{head}"
def cut_patch(self, *commits: str) -> subprocess.CompletedProcess[str]:
return subprocess.run([sys.executable, str(TOOL), "--cut-patch", *commits, str(self.target)], capture_output=True, cwd=self.clone, env=self.env, text=True)
def test_cuts_a_patch_of_the_newest_tag_holding_only_the_named_commits_then_merges_the_tag_back_and_deploys_it(self):
ran = self.cut_patch(self.plan_patch())
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertEqual(self.origin_git("cat-file", "-t", "v0.1.1").strip(), "tag", "the tag is annotated")
self.assertEqual(self.origin_git("tag", "-l", "--format=%(contents:subject)", "v0.1.1").strip(), "Cut release 0.1.1")
self.assertEqual(self.origin_git("log", "-1", "--format=%s", "v0.1.1").strip(), "Cut release 0.1.1")
self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}~1"), self.origin_git("rev-parse", "v0.1.0^{commit}"))
self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n")
self.assertEqual(self.origin_git("show", "v0.1.1:CHANGELOG.md"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
self.assertEqual(self.origin_git("show", "v0.1.1:todo.md"), self.origin_git("show", "v0.1.0:todo.md"))
self.assertNotIn("feature.txt", self.origin_git("ls-tree", "--name-only", "v0.1.1"))
self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main")
self.assertEqual(self.origin_git("log", "-1", "--format=%s", "main").strip(), "Merge release 0.1.1 into main")
self.assertEqual(self.origin_git("show", "main:CHANGELOG.md"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
self.assertEqual(self.origin_git("show", "main:feature.txt"), "new\n")
self.assertIn(["tea", "pulls", "create", "--head", "release-0.1.1", "--base", "main"], [call[:7] for call in self.forge_state()["calls"]])
self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "v0.1.1")
self.assertIn("Done: v0.1.1 is cut and pushed", ran.stdout)
def test_takes_one_commit_as_the_patch(self):
head = self.plan_patch().split("..")[1]
ran = self.cut_patch(head)
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n")
def test_refuses_changing_nothing_where_the_plan_names_no_patch_release(self):
self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix tool.txt")
self.git(self.clone, "push", "-q", "origin", "main")
ran = self.cut_patch("HEAD")
self.assertEqual(ran.returncode, 1)
self.assertIn("0.1.1", ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
self.assertEqual(self.forge_state()["pulls"], [])
def test_refuses_changing_nothing_while_the_patch_release_holds_an_item(self):
self.plan_patch()
self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=4, release="0.1.1")}, "File item 4")
self.git(self.clone, "push", "-q", "origin", "main")
ran = self.cut_patch("HEAD~1")
self.assertEqual(ran.returncode, 1)
self.assertIn("still holds items", ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
def test_skips_the_release_review_a_patch_would_otherwise_wait_for(self):
self.git(self.clone, "reset", "-q", "--hard", "HEAD~1")
self.git(self.clone, "push", "-q", "--force", "origin", "main")
ran = self.cut_patch(self.plan_patch())
self.assertEqual(ran.returncode, 0, ran.stderr)
def test_refuses_a_commit_the_tag_holds_or_origins_main_doesnt(self):
self.plan_patch()
for commit in ("v0.1.0", "HEAD"):
if commit == "HEAD":
self.commit({"tool.txt": "local\n"}, "Unpushed")
ran = self.cut_patch(commit)
self.assertEqual(ran.returncode, 1, commit)
self.assertIn(self.git(self.clone, "rev-parse", "--short", f"{commit}^{{commit}}").strip()[:7], ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self):
self.plan_patch()
self.commit({"tool.txt": "fixed again\n"}, "Fix more")
self.git(self.clone, "push", "-q", "origin", "main")
ran = self.cut_patch("HEAD")
self.assertEqual(ran.returncode, 1)
self.assertIn("## Unreleased", ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
def test_stops_before_tagging_where_ci_fails_on_the_patch(self):
ran = self.cut_patch(self.plan_patch({"ci.sh": "echo the suite failed >&2\nexit 1\n"}))
self.assertEqual(ran.returncode, 1)
self.assertIn("ci.sh", ran.stderr)
self.assertIn("the suite failed", ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
self.assertEqual(self.git(self.clone, "tag", "-l", "v0.1.1"), "")
self.assertEqual(self.forge_state()["pulls"], [])
def test_stops_naming_the_commit_that_does_not_apply_on_the_tag(self):
self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main")
ran = self.cut_patch(self.plan_patch())
self.assertEqual(ran.returncode, 1)
self.assertIn("Fix item 3", ran.stderr)
self.assertIn("v0.1.0", ran.stderr)
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
def test_a_rerun_after_a_failed_merge_back_check_keeps_the_pushed_tag_and_merges_back(self):
self.set_checks("failure")
commits = self.plan_patch()
ran = self.cut_patch(commits)
self.assertEqual(ran.returncode, 1)
tagged = self.origin_git("rev-parse", "v0.1.1^{commit}")
self.set_checks("success")
ran = self.cut_patch(commits)
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}"), tagged)
self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main")
def test_plain_cut_refuses_a_patch_release_and_names_cut_patch(self):
self.plan_patch()
ran = self.cut()
self.assertEqual(ran.returncode, 1)
self.assertIn("--cut-patch", ran.stderr)
self.assertEqual(self.forge_state()["pulls"], [])
def test_cut_patch_needs_its_commits(self):
ran = subprocess.run([sys.executable, str(TOOL), "--cut-patch"], capture_output=True, cwd=self.clone, env=self.env, text=True)
self.assertEqual(ran.returncode, 1)
self.assertIn("usage", ran.stderr)
self.assertEqual(self.forge_state()["calls"], [])
def test_takes_no_option_but_cut(self):
ran = subprocess.run([sys.executable, str(TOOL), "--cut", "--force"], capture_output=True, cwd=self.clone, env=self.env, text=True)
self.assertEqual(ran.returncode, 1)