diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index 5e31b394..4f349905 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -139,7 +139,7 @@ def tagged_entries(clone: str, patch: Patch) -> Failure | None: return changelog listed = [line for line in section(changelog, re.escape(patch.named)) or [] if line.strip()] if listed != patch.entries: - return Failure(f"origin's v{patch.named} lists other changelog entries than the commits named: name the commits it was cut from") + return Failure(f"origin's v{patch.named} lists other changelog entries under ## {patch.named} than the commits named added under ## Unreleased. The tag lists:\n" + "\n".join(listed) + "\nThe commits added:\n" + "\n".join(patch.entries)) return None @@ -192,8 +192,9 @@ def apply_commit(clone: str, worktree: pathlib.Path, commit: str, patch: Patch) subject = git("log", "-1", "--format=%s", commit, cwd=clone) return Failure( f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {patch.base}: {applied.reason}. " - f"Cut the patch by hand: on {patch.base}, apply the fix and add CHANGELOG.md's ## {patch.named} section, commit that titled `Cut release {patch.named}`, " - f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun then merges it back and deploys it." + f"Cut the patch by hand: on {patch.base}, apply the fix and add a ## {patch.named} section to CHANGELOG.md, commit that titled `Cut release {patch.named}`, " + f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun with the same commits then merges it back and deploys it, " + f"where the section holds exactly these lines:\n" + "\n".join(patch.entries) ) return None diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index 8ed6f5d8..c8d2499e 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -578,6 +578,24 @@ class Cut(unittest.TestCase): self.assertEqual(self.forge_state()["calls"], []) self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + def test_a_rerun_merges_back_and_deploys_a_patch_cut_by_hand_as_the_refusal_says(self): + self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main") + commits = self.plan_patch() + refused = self.cut_patch(commits) + self.assertEqual(refused.returncode, 1) + self.assertIn("exactly these lines:\n- Fixed.", refused.stderr) + self.git(self.clone, "switch", "-q", "--detach", "v0.1.0") + self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Cut release 0.1.1") + self.git(self.clone, "tag", "-a", "v0.1.1", "-m", "Cut release 0.1.1") + self.git(self.clone, "push", "-q", "origin", "v0.1.1") + self.git(self.clone, "switch", "-q", "main") + tagged = self.origin_git("rev-parse", "v0.1.1^{commit}") + 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") + self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "v0.1.1") + def test_a_rerun_refuses_a_pushed_tag_cut_from_other_commits(self): self.set_checks("failure") commits = self.plan_patch() @@ -587,7 +605,7 @@ class Cut(unittest.TestCase): self.set_checks("success") ran = self.cut_patch("HEAD") self.assertEqual(ran.returncode, 1) - self.assertIn("other changelog entries", ran.stderr) + self.assertIn("The tag lists:\n- Fixed.\nThe commits added:\n- Fixed twice.", ran.stderr) self.assertNotIn("Fixed twice", self.origin_git("show", "main:CHANGELOG.md").split("## 0.1.0")[0].split("## Unreleased")[0]) def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self):