Answer stability round 1: 1 🔴, 3 🟡 (0 misread); drop cut tags no run pushed, split the fork and checks tests, test the usage error
This commit is contained in:
+22
-14
@@ -24,6 +24,8 @@ def cut(clone: str, checkout: str) -> str | Failure:
|
||||
return same
|
||||
if isinstance(fetched := git("fetch", "--quiet", "--tags", "origin", cwd=clone), Failure):
|
||||
return fetched
|
||||
if isinstance(dropped := drop_unpushed_cut_tags(clone), Failure):
|
||||
return dropped
|
||||
ref = default_ref(cwd=clone)
|
||||
if isinstance(ref, Failure):
|
||||
return ref
|
||||
@@ -44,13 +46,11 @@ def cut(clone: str, checkout: str) -> str | Failure:
|
||||
return Failure(f"the pull request merged, but {ref} holds no commit titled {title!r}")
|
||||
if isinstance(merged, Failure):
|
||||
return merged
|
||||
made = tag_commit(tag, title, merged, clone)
|
||||
if isinstance(made, Failure):
|
||||
if isinstance(made := git("tag", "--annotate", "--message", title, tag, merged, cwd=clone), Failure):
|
||||
return made
|
||||
if isinstance(pushed := git("push", "--quiet", "origin", f"refs/tags/{tag}", cwd=clone), Failure):
|
||||
# A tag only the clone holds would read as cut, so every rerun would refuse.
|
||||
if made:
|
||||
git("tag", "--delete", tag, cwd=clone)
|
||||
# Until a rerun, chunk-preflight would read a tag only the clone holds as cut.
|
||||
git("tag", "--delete", tag, cwd=clone)
|
||||
return pushed
|
||||
moved = deploy(checkout)
|
||||
if isinstance(moved, Failure):
|
||||
@@ -58,6 +58,23 @@ def cut(clone: str, checkout: str) -> str | Failure:
|
||||
return f"Cut {tag}.\n\n{moved}"
|
||||
|
||||
|
||||
def drop_unpushed_cut_tags(clone: str) -> Failure | None:
|
||||
"""Delete each v* tag the clone holds but origin doesn't, where it tags a commit titled `Cut release <its version>`: one a run made and never pushed, such as a run that died between the two. The clone reads cut releases from its own tags, so such a tag would read as a cut nobody published."""
|
||||
local = git("tag", "--list", "v*", "--format=%(refname:short) %(*subject)", cwd=clone)
|
||||
remote = git("ls-remote", "--tags", "--refs", "origin", "refs/tags/v*", cwd=clone)
|
||||
if isinstance(local, Failure):
|
||||
return local
|
||||
if isinstance(remote, Failure):
|
||||
return remote
|
||||
pushed = {line.split("refs/tags/", 1)[-1] for line in remote.splitlines()}
|
||||
for line in local.splitlines():
|
||||
tag, _, subject = line.partition(" ")
|
||||
if tag not in pushed and subject == f"Cut release {tag.removeprefix('v')}":
|
||||
if isinstance(deleted := git("tag", "--delete", tag, cwd=clone), Failure):
|
||||
return deleted
|
||||
return None
|
||||
|
||||
|
||||
def same_origin(clone: str, checkout: str) -> Failure | None:
|
||||
"""A Failure unless clone is a clone of the origin checkout takes its releases from, so --cut never cuts another project."""
|
||||
urls = [git("ls-remote", "--get-url", "origin", cwd=where) for where in (clone, checkout)]
|
||||
@@ -167,12 +184,3 @@ def push_cut_commit(clone: str, ref: str, branch: str, named: str, title: str, r
|
||||
finally:
|
||||
git("worktree", "remove", "--force", str(worktree), cwd=clone)
|
||||
shutil.rmtree(worktree.parent, ignore_errors=True)
|
||||
|
||||
|
||||
def tag_commit(tag: str, title: str, commit: str, clone: str) -> bool | Failure:
|
||||
"""Tag commit as tag, annotated with title, unless an earlier run did: whether this call made the tag. A Failure where tag already names another commit."""
|
||||
existing = git("rev-parse", "--verify", "--quiet", f"refs/tags/{tag}^{{commit}}", cwd=clone)
|
||||
if not isinstance(existing, Failure):
|
||||
return False if existing.strip() == commit else Failure(f"{tag} already tags {existing.strip()[:12]}, not the merged commit {commit[:12]}")
|
||||
made = git("tag", "--annotate", "--message", title, tag, commit, cwd=clone)
|
||||
return made if isinstance(made, Failure) else True
|
||||
|
||||
Reference in New Issue
Block a user