Skip to content

Conversation

@cseeman
Copy link
Contributor

@cseeman cseeman commented Dec 19, 2025

Replaces complex branch deletion logic with git checkout -B which handles all scenarios reliably.

Problem

During CI release workflow, rake release failed when trying to recreate the finalize/ branch:
error: cannot delete branch 'finalize/0.4.8' used by worktree

The old logic tried to delete and recreate existing branches, which fails when you're on that
branch.

Solution

Use git checkout -B which:

  • Creates branch if it doesn't exist
  • Resets to current HEAD if branch exists (even if you're on it)

This handles CI runs, local retries, and all edge cases with one command.

Test plan

  • Added test for retry scenarios (same branch, different branch)
  • All 101 tests passing

@cseeman cseeman requested a review from a team as a code owner December 19, 2025 20:27
@cseeman cseeman force-pushed the fix-branch-task-current-branch branch from 8e2d92b to c2d1629 Compare December 19, 2025 20:43
Handles all scenarios reliably:
- CI fresh runs (creates branch)
- Local retries on different branch (resets existing branch)
- Local retries on same branch (stays on branch)

Added test for retry scenarios to prevent regressions.

Fixed: Branch task fails trying to delete current branch
Version: patch

Co-Authored-By: Claude <noreply@anthropic.com>
@cseeman cseeman force-pushed the fix-branch-task-current-branch branch from c2d1629 to e8e74eb Compare December 19, 2025 20:47
@cseeman cseeman changed the title Skip branch task when already on target branch Simplify branch task with git checkout -B Dec 19, 2025
end
run_command("git checkout -b #{branch_name}", "Failed to create and checkout branch #{branch_name}")
# Create branch or reset if exists (-B flag handles both cases)
run_command("git checkout -B #{branch_name}", "Failed to checkout branch #{branch_name}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were worried about CI vs local run of this rake, yes, git checkout -B works identically in both environments:

Scenario CI Local Behavior
Branch doesn't exist Creates branch at HEAD
Branch exists, on different branch Switches to branch, resets to HEAD
Branch exists, already on it Stays on branch, resets to HEAD
Dirty working tree Fails safely (won't lose uncommitted changes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants