Public Access
fix: branch_rename force-updates target ref instead of delete+recreate #335
Reference in New Issue
Block a user
Delete Branch "fix/promote-rc-force-update"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
cli/branch_rename.php(exposed as themoko repo:rename-branchCLI command,bin/moko:182) renamed a branch by deleting the target and recreating it. When the target is a protected branch (e.g.rc), the delete fails — silently — and the recreate then returns HTTP 409 "branch already exists", so the rename never happens.Fix
Force-update the target ref in place instead: read the source branch HEAD, and if the target already exists
PATCH git/refs/heads/{to}with{sha, force:true}; otherwise create it viaPOST /branches.php -lclean, phpcs PSR-12 clean.Context
The
auto-release.yml"Promote to RC" job that used to call this script has since been changed to do the rename inline in the workflow (Template-Generic PR #52), so promote-rc no longer depends on this script. This fix remains valuable for the standalonemoko repo:rename-branchcommand, which would otherwise hit the same failure when renaming into a protected branch.Both paths require the caller's token to have force-push permission on a protected target branch.
https://claude.ai/code/session_01Wsno14cxE49MstXFs9G5KT
branch_rename.php deleted the target branch then recreated it. When the target (rc) is a protected branch, the delete silently fails and the recreate returns HTTP 409 'branch already exists', breaking every PR-to-main promote-rc. Force-update the ref in place via PATCH git/refs/heads/{to} (sha+force) when the target exists; still create it when it doesn't. Requires the CI token to have force-push permission on the protected rc branch.e79908f275toc7a26c1ce1