Repository navigation
Delete the remote branch when release deletes a PR-merged branch - #3
Merged
Merged
Conversation
./dev worktree release deleted origin/<branch> only on the merged-PR path. When git branch -d succeeded (for example a squash-merged branch whose upstream still exists), the remote branch survived. Release now captures the local tip before deleting and, on either path, deletes origin/<branch> with --force-with-lease=<branch>:<tip>, so a remote that has moved is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git branch -d passes any branch that is merged into its upstream, so a branch pushed with -u and never merged passed it, and release then deleted its remote branch (closing any open PR). The remote delete now requires a PR merged at exactly the local tip, on both the -d and the -D paths. The lease and the delete name refs/heads/<branch>, so a same-named tag cannot make the push ambiguous. Tests share commit, gitIn and ghSays helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
./dev worktree release <branch>now deletesorigin/<branch>when a PR merged the branch, including whengit branch -dsucceeds, for example a squash-merged branch whose upstream still exists. Before this change, only the-Dpath deleted the remote branch, so on the-dpath it had to be removed by hand. The remote branch is deleted only while it is still at the local tip.Gates
./dev test(every required lane).test-ai-results/summary.md: format, vet, lint, unit, coverage, file-length, imports, versions, docs-check all PASS,Overall: PASSdevtools/internal/dev/worktree_test.go, real git with a bare origin):TestWorktreeDeletesTheRemoteOfAMergedBranchWithAnUpstream: push-u, PR merged at the tip, release. The local branch and the origin'srefs/heads/feat/pare both gone.TestWorktreeKeepsAMovedRemoteBranch: origin moved past the local tip after the PR merged. The local branch is deleted, the remote survives at the newer commit, and no remote delete is reported.TestWorktreeKeepsTheRemoteOfAnUnmergedPushedBranch: push-uwith no PR.-dpasses, but the remote survives.TestWorktreeKeepsUnmergedBranch: now also pushes the branch and asserts that the remote of a kept branch survives.origin/mainfails the merged-with-upstream test.Rulings
Ruling (risk: low): the remote delete requires a PR merged at exactly the local tip, on both the
-dand-Dpaths, as well as the--force-with-lease=refs/heads/<branch>:<tip>lease.Why: when a branch has an upstream,
git branch -dchecks only that upstream, so a branch pushed with-uand never merged passes it. Deleting its remote then would close an open PR and drop the only remote copy. A PR check is used instead of an ancestor-of-main check because a squash-merged tip is never an ancestor of main.If wrong: a branch merged without a PR (pushed straight to main) keeps its remote branch, which can be deleted by hand. Nothing is lost.
Ruling (risk: low): the lease and the delete name
refs/heads/<branch>, not the short name.Why: if origin has a tag with the same name, the short name makes the push ambiguous.
If wrong: none. Both forms name the same branch.
Review
devtools/internal/dev/worktree.godeleteBranch: the PR gate and the ordering of-dand-D.deleteRemoteBranch: the lease semantics.Deviations
The task said to delete the remote after any successful
-dif it was at the local tip. This PR also requires a merged PR at that tip; see Rulings. Otherwise none.🤖 Generated with Claude Code