fix: branch_rename force-updates target ref instead of delete+recreate #335

Merged
jmiller merged 1 commits from fix/promote-rc-force-update into main 2026-07-04 23:26:40 +00:00
Owner

Summary

cli/branch_rename.php (exposed as the moko repo:rename-branch CLI 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 via POST /branches. php -l clean, 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 standalone moko repo:rename-branch command, 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

## Summary `cli/branch_rename.php` (exposed as the `moko repo:rename-branch` CLI 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 via `POST /branches`. `php -l` clean, 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 **standalone `moko repo:rename-branch` command**, 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
jmiller added 1 commit 2026-07-04 23:26:11 +00:00
fix: promote-rc force-updates target ref instead of delete+recreate
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Failing after 9s
Universal: Build & Release / Promote to RC (pull_request) Has been skipped
Universal: PR Check / Secret Scan (pull_request) Successful in 13s
Universal: PR Check / Validate PR (pull_request) Successful in 9s
Generic: Repo Health / Access control (pull_request) Successful in 3s
Generic: Repo Health / Site Health (pull_request) Has been skipped
RC Revert / Rename rc/ back to dev/ (pull_request) Has been skipped
Branch Cleanup / Delete merged branch (pull_request) Successful in 3s
Universal: Build & Release / Build & Release Pipeline (pull_request) Successful in 44s
Generic: Project CI / Lint & Validate (pull_request) Successful in 1m7s
Platform: mokocli CI / Gate 1: Code Quality (pull_request) Successful in 1m52s
Universal: Workflow Sync Trigger / Sync workflows to live repos (pull_request) Failing after 8m27s
Generic: Project CI / Tests (pull_request) Has been cancelled
Platform: mokocli CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: mokocli CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: mokocli CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: mokocli CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: mokocli CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: mokocli CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: mokocli CI / CI Summary (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Generic: Repo Health / Report: Scripts Governance (pull_request) Has been cancelled
Generic: Repo Health / Report: Repository Health (pull_request) Has been cancelled
c7a26c1ce1
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.
jmiller force-pushed fix/promote-rc-force-update from e79908f275 to c7a26c1ce1 2026-07-04 23:26:11 +00:00 Compare
jmiller merged commit 120dbe3be2 into main 2026-07-04 23:26:40 +00:00
jmiller deleted branch fix/promote-rc-force-update 2026-07-04 23:26:44 +00:00
Sign in to join this conversation.
No Reviewers
No labels
Priority -
Type -
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MokoConsulting/MokoCLI#335