Skip to content

fix(worktree): never rebase an already-pushed item branch; follow origin instead - #847

Merged
getappz merged 1 commit into
masterfrom
task/331-rebase-item-worktree-rewrites-an-already
Oct 3, 2026
Merged

getappz merged 1 commit into
masterfrom
task/331-rebase-item-worktree-rewrites-an-already

Conversation

@getappz

@getappz getappz commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Fixes the merge-vs-rebase fight observed on PR #844 for item #331 .

What happened

  1. The in_review sweep saw the PR Behind and ran pulls::update_branch; GitHub added a Merge branch 'master' into … commit to the remote branch.
  2. CI went red, the supervisor dispatched a self-repair job, and that job's claim ran rebase_item_worktree, which rebased the local worktree branch onto master without looking at origin/<branch>.
  3. Local history (rewritten commits) and remote history (original commits + merge) diverged; the next push would have had to merge the originals back on top of their rewritten copies.

Fix

rebase_item_worktree now fetches the worktree's own branch first. If it exists on origin, the branch is followed, never rebased:

  • remote moved ahead (update-branch merge, a fixup pushed elsewhere) → git merge --ff-only origin/<branch> → new RebaseOutcome::FollowedRemote
  • both sides moved → new RebaseOutcome::Diverged, nothing touched (push_branch's integrate path handles it)
  • local equal or ahead → UpToDate, no rebase
    A branch that was never pushed rebases exactly as before (item remove engram #161's case). push_branch logs the two new outcomes; the MCP claim path already matched with _.

Tests

New crates/flare-git-core/src/worktree_rebase_tests.rs (worktree_tests.rs sits at the 1500-line gate): pushed branch follows the remote's merge with the original SHA kept as an ancestor; pushed branch untouched when only the target moved; diverged branch untouched; never-pushed branch still rebases. cargo nextest run -p flare-git-core 255/255; clippy -D warnings clean on flare-git-core and agentflare.

Summary by CodeRabbit

  • Improvements
    • Worktrees for branches already pushed to the remote now follow remote updates when the remote branch is ahead, without rewriting existing commits.
    • If local and remote branch histories have diverged, the worktree remains unchanged.
    • Branches without an established remote state continue to rebase onto the latest target branch.

…gin instead

Once a branch is on origin its PR owns base drift (the supervisor merges the
base in via GitHub's update-branch). Rebasing the local worktree then only
makes the two histories diverge. Fetch the branch's own remote copy first:
fast-forward when the remote moved (FollowedRemote), leave both-moved alone
(Diverged), and rebase only a branch that was never pushed.

Agentflare-Agent: claude-code
Agentflare-Branch: task/331-rebase-item-worktree-rewrites-an-already
Agentflare-Item: 331
Agentflare-Session: 10553a88-a912-4153-97c7-8d172ee44d92
@getappz

getappz commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

Tracking this PR for automated review (flared:51bb8de6c33b).

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: getappz/agentflare/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: c58ddbec-9e8e-455b-a1af-8ac044500447
📥 Commits

Reviewing files that changed from the base of the PR and between 4ae7b1d and d873629.

📒 Files selected for processing (2)
  • crates/flare-git-core/src/worktree.rs
  • crates/flare-git-core/src/worktree_rebase_tests.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

The worktree rebase path now checks the current branch on origin before rebasing onto the target branch. It fast-forwards when the remote is ahead, leaves divergent histories unchanged, and retains the existing target-rebase path when remote state is unavailable.

Changes

Remote branch following

Layer / File(s) Summary
Detect and handle pushed branch state
crates/flare-git-core/src/worktree.rs, crates/flare-git-core/src/worktree_rebase_tests.rs
rebase_item_worktree checks for a pushed branch before the target-rebase path. follow_pushed_branch fetches the branch from origin and reports UpToDate or Diverged, or fast-forwards and reports FollowedRemote. Tests cover pushed branches with remote updates, target-only updates, diverged histories, and never-pushed branches.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant rebase_item_worktree
  participant follow_pushed_branch
  participant origin
  participant worktree
  rebase_item_worktree->>follow_pushed_branch: Check current pushed branch
  follow_pushed_branch->>origin: Fetch current branch
  origin-->>follow_pushed_branch: Remote-tracking ref or fetch failure
  alt Remote is ahead
    follow_pushed_branch->>worktree: Fast-forward to remote tip
    worktree-->>follow_pushed_branch: Fast-forward result
    follow_pushed_branch-->>rebase_item_worktree: Return FollowedRemote
  else Up to date or diverged
    follow_pushed_branch-->>rebase_item_worktree: Return status without changing HEAD
  else Remote state unavailable
    follow_pushed_branch-->>rebase_item_worktree: Return no result
  end
Loading

Merge Risk: ⚪ Minimal · up to d8736

No actionable issue remains from the reviewed change; it is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: pushed item branches follow their remote instead of being rebased.
Description check ✅ Passed The description explains the problem and fix, and reports test and clippy results. It does not use the template headings or address the reviewer notes on risks and backwards compatibility, but the mai…
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@getappz
getappz merged commit 7cca639 into master Oct 3, 2026
19 checks passed
@getappz
getappz deleted the task/331-rebase-item-worktree-rewrites-an-already branch October 3, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant