Skip to content

fix(rebase): handle upstream submodule updates - #93

Merged
cheat2001 merged 3 commits into
cheat2001:mainfrom
ChrisLauinger77:fix/rebase-submodule-drift
Nov 14, 2026
Merged

cheat2001 merged 3 commits into
cheat2001:mainfrom
ChrisLauinger77:fix/rebase-submodule-drift

Conversation

@ChrisLauinger77

@ChrisLauinger77 ChrisLauinger77 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What & why

Pull with rebase fails when upstream changes a submodule's recorded commit and the local branch has commits to replay. The parent index advances while the submodule checkout stays at its old commit, so libgit2 refuses each replay commit with “unstaged changes exist in workdir.” Continue rebase hits the same failure.

This fixes rebase, explicit/configured Pull with rebase, and Continue, including a rebase left stuck by an older client. Closes #89.

Implementation

  • Use one helper at all three replay commit sites. Try libgit2's normal commit first, and inspect submodules only after its unstaged-worktree rebase error. Optional enumeration/status failures retain the original libgit2 result. For initialized submodules with commit drift and no tracked edits inside, temporarily attach a pathless in-memory copy of the index with only those gitlinks marked valid. Restore the original index on every exit path.
  • Keep libgit2's commit creation, already-applied handling, reflog updates and rewritten mappings. Ordinary unstaged files, dirty submodules and unresolved conflicts still block committing. The workaround writes no config or disk-index flags and does not move submodule checkouts.
  • Preserve post-hook timing and Skip hooks across pauses. App rebase/pull/Continue save eligible submodule baselines across pauses and failed attempts. For an older-client rebase without a saved baseline, recover eligibility from its original HEAD tree: clean checkouts still at those gitlinks follow the completed rebase's recorded commits before post-rewrite runs. Saved baselines exclude later deliberate moves, including a move back to the pre-rebase commit. Publish baselines through a synced temporary file and atomic replacement, so a partial write cannot truncate the live snapshot. Saving failures are logged without replacing the operation's success, conflict status or original error. Invalid baseline metadata stops Continue instead of guessing.
  • Add fifteen integration tests and two atomic-publication module tests covering pull modes, multiple replay commits, app-level older-client recovery, conflicts/abort, resolved gitlinks, already-applied steps, Continue rebase drops the commit a rebase stopped on when replay fails without a conflict #88's stopped-step recovery, dirty files, lock failures and hook mappings. Recovery checks require an updated submodule before post-rewrite, no pointer rollback after Stage all, retry after an error, preservation of deliberate moves, and refusal of invalid recovery metadata. Additional regressions preserve conflict outcomes and Continue rebase drops the commit a rebase stopped on when replay fails without a conflict #88's blocker messages when baseline publication fails, keep the old baseline during partial writes, and replay ordinary file commits with intermediate malformed .gitmodules.
  • Update the changelog and CLAUDE.md. Based on main after fix(discard): discard staged changes under one index lock #91 merged; its discard tests pass alongside this fix.

Validation

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test: 323 passed on macOS — 112 unit tests, 210 engine tests and one clone-hook test. Run with an isolated test home/Git configuration; local TCP fixtures ran outside the sandbox.
  • pnpm typecheck and pnpm test: all workspace typechecks and 341 frontend tests pass.
  • git diff --check

Screenshots

Not applicable; no UI changes.

Checklist

  • pnpm typecheck && pnpm test pass
  • cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test pass
  • New engine behavior has integration tests in tests/git_engine.rs
  • Existing undo wrappers remain in place; no new commands
  • No UI/color changes
  • CLAUDE.md updated
  • Commits carry no trailers from coding tools

Use a temporary in-memory index during replay commits so an unchanged submodule checkout does not block rebase or Continue. Keep normal dirty-file checks and restore the repository index on every exit path.

Add regression coverage for pull modes, older-client recovery, conflicts, abort, hooks, gitlink resolution and failed commits. Fixes cheat2001#89.
Recover eligible submodule checkouts from the original rebase tree when no app baseline exists. Save baselines across pauses and failed attempts so intentional checkout moves remain excluded from automatic updates.

Exercise recovery through the app wrapper, require an updated checkout before post-rewrite and verify Stage all cannot revert the upstream gitlink. Cover retry, deliberate moves, blocked replay and invalid recovery metadata.
Publish synced baseline snapshots through an atomic tempfile replacement and preserve rebase outcomes when saving recovery metadata fails. Keep the old snapshot intact on partial writes.

Try normal replay commits before inspecting submodules and retain the original libgit2 error when optional inspection fails. Cover atomic publication, partial write failures, conflict and blocker outcomes, and intermediate malformed gitmodules.
@cheat2001
cheat2001 merged commit 9aceb60 into cheat2001:main Nov 14, 2026
6 checks passed
@ChrisLauinger77
ChrisLauinger77 deleted the fix/rebase-submodule-drift branch November 14, 2026 12:24
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.

Pull with rebase fails when the upstream moved a submodule to a new commit

2 participants