From 6dda50c7bde799530c760ea9235695987907d006 Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Sun, 15 Nov 2026 15:39:42 -0700 Subject: [PATCH 1/2] fix: lease the major tag on the state the release checks ran against The lease came from an ls-remote after the fetch and the checks. A release that landed in between became the lease, and the push moved the major tag back from it. The script now reads the remote tags before the fetch, stops when the fetch brings a different major tag, checks the remote again after the prompt, and leases the major tag on the snapshot. The snapshot comes from the remote, not the local tag, because a failed push of a new major leaves a local tag the remote never had. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011baD3hG81A9qbFYrSn1ysE --- script/release | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/script/release b/script/release index b8d4a88..8a398fd 100755 --- a/script/release +++ b/script/release @@ -35,6 +35,11 @@ die() { branch=$(git rev-parse --abbrev-ref HEAD) [ "$branch" = "$release_branch" ] || die "On $branch - releases are cut from $release_branch." +# The remote's tags before the fetch. The push below may only move the major +# tag from the object it has here, so a release that lands any time after this +# line makes the push fail instead of being overwritten. +remote_tags=$(git ls-remote --tags "$remote") + # --force because a run that failed mid-push leaves the local major tag moved # ahead of the remote, and a plain fetch refuses to rewind it. git fetch --tags --force "$remote" "$release_branch" @@ -81,9 +86,19 @@ fi echo -e "Latest release: ${BLUE}${latest_tag:-none}${OFF}" echo -e "New release: ${BLUE}${new_tag}${OFF} at $(git log -1 --format='%h %s')" -# What the remote has right now, so the push can refuse to clobber a release -# someone else lands while this one sits at the prompt. Empty when absent. -major_remote=$(git ls-remote "$remote" "refs/tags/$major_tag" | cut -f1) +# The major tag as the remote had it before the fetch; empty when absent. Not a +# fresh ls-remote: that could pick up a release that landed after the checks +# above, and the push would then move the major tag back from it. Not the +# local tag either: a run that failed mid-push for a new major leaves a local +# tag the remote never had. +major_expected=$(awk -v ref="refs/tags/$major_tag" '$2 == ref { print $1 }' <<<"$remote_tags") + +# A release that landed during the fetch: the checks and the tag shown below +# would describe it, not the state the lease holds. +if [ -n "$major_expected" ] && + [ "$(git rev-parse -q --verify "refs/tags/$major_tag" || true)" != "$major_expected" ]; then + die "$major_tag changed on $remote while this release was starting - run script/release again." +fi if git rev-parse -q --verify "refs/tags/$major_tag" >/dev/null; then major_exists='yes' @@ -99,6 +114,11 @@ echo 'Every workflow on the major tag picks this up immediately.' read -r -p 'Tag and push? [y/N] ' reply || reply='' [[ $reply =~ ^[Yy]$ ]] || die 'Aborted - nothing was tagged.' +# A release that landed while the prompt waited. The lease would refuse the +# push anyway; this stops before anything is tagged and says why. +[ "$(git ls-remote "$remote" "refs/tags/$major_tag" | cut -f1)" = "$major_expected" ] || + die "$major_tag changed on $remote since the checks ran - nothing was tagged. Run script/release again." + [ "$resuming" = 'yes' ] || git tag --annotate --message "$new_tag" "$new_tag" git tag --annotate --force --message "Sync $major_tag with $new_tag" "$major_tag" @@ -108,7 +128,7 @@ git tag --annotate --force --message "Sync $major_tag with $new_tag" "$major_tag # The major tag deliberately carries no '+'. --force-with-lease does the # forcing, and a '+' in the refspec forces unconditionally and silently # bypasses the lease, which would make the guard below do nothing. -git push --atomic --force-with-lease="refs/tags/$major_tag:$major_remote" "$remote" \ +git push --atomic --force-with-lease="refs/tags/$major_tag:$major_expected" "$remote" \ "refs/tags/$new_tag:refs/tags/$new_tag" \ "refs/tags/$major_tag:refs/tags/$major_tag" From ad26ed80fc2a11282b03bf05308404f6b6e2aaa6 Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Sun, 15 Nov 2026 15:42:10 -0700 Subject: [PATCH 2/2] fix: read only the exact major tag line from ls-remote The check after the prompt took every line ls-remote printed for the major tag. A git that also lists the peeled commit of an annotated tag (refs/tags/vN^{}) would give two IDs, and the check would stop every release of an existing major. It now keeps only the refs/tags/vN line, as the snapshot before the fetch already does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011baD3hG81A9qbFYrSn1ysE --- script/release | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/release b/script/release index 8a398fd..821880b 100755 --- a/script/release +++ b/script/release @@ -116,7 +116,11 @@ read -r -p 'Tag and push? [y/N] ' reply || reply='' # A release that landed while the prompt waited. The lease would refuse the # push anyway; this stops before anything is tagged and says why. -[ "$(git ls-remote "$remote" "refs/tags/$major_tag" | cut -f1)" = "$major_expected" ] || +# Only the exact line counts: an annotated tag can also list its peeled +# commit as refs/tags/vN^{}. +major_now=$(git ls-remote --tags "$remote" "refs/tags/$major_tag" | + awk -v ref="refs/tags/$major_tag" '$2 == ref { print $1 }') +[ "$major_now" = "$major_expected" ] || die "$major_tag changed on $remote since the checks ran - nothing was tagged. Run script/release again." [ "$resuming" = 'yes' ] || git tag --annotate --message "$new_tag" "$new_tag"