strategy: replay local checkpoints when fetch finds a diverged remote#1251
Open
pjbgf wants to merge 7 commits into
Open
strategy: replay local checkpoints when fetch finds a diverged remote#1251pjbgf wants to merge 7 commits into
pjbgf wants to merge 7 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the strategy layer’s ref-promotion logic so that fetching a checkpoint/metadata ref to a new remote tip won’t orphan local-only checkpoint commits when the local ref has diverged or is disconnected from the fetched tip.
Changes:
- Introduces an
errNoMergeBasesentinel and teachesgetMergeBaseto return it whengit merge-basereports “no common ancestor”. - Refactors
SafelyAdvanceLocalRefto branch based on merge-base outcomes and replay local-only commits onto the fetched tip viacherryPickOntowhen appropriate. - Adds regression tests for diverged and disconnected metadata-branch fetch scenarios to ensure local-only checkpoint blobs remain present after fetch.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/entire/cli/strategy/push_common.go | Updates merge-base handling to distinguish “no merge base” from other failures. |
| cmd/entire/cli/strategy/common.go | Reworks SafelyAdvanceLocalRef to prevent dropping local-only commits by replaying them when diverged/disconnected. |
| cmd/entire/cli/strategy/checkpoint_remote_test.go | Adds tests covering diverged and disconnected fetch promotions preserving local-only checkpoints. |
SafelyAdvanceLocalRef only short-circuited when local was equal to or
strictly ahead of targetHash; every other state (missing, behind,
diverged, disconnected) flowed into the same SetReference call.
That was correct for "missing" (initialize) and "behind" (fast-forward),
because targetHash already contains everything reachable from local. It
was wrong for the diverged and disconnected cases: local-only checkpoint
commits that hadn't been pushed yet were left as orphans the moment any
caller (resume, doctor, the read-side metadata fetch) advanced the local
ref to a remote tip that didn't contain them.
Split the post-equality branch on git-merge-base instead:
mergeBase == targetHash -> local ahead, no-op
mergeBase == localHash -> local behind, fast-forward (unchanged)
mergeBase exists, neither -> diverged, cherryPickOnto local-only commits
errNoMergeBase -> disconnected, cherryPickOnto full local chain
The fast-forward path still goes through the same setRefHash call as
before, so the existing "behind" behavior is preserved by construction.
The diverged and disconnected paths now replay local-only commits onto
targetHash via cherryPickOnto, which preserves the original Author and
stamps the local user as Committer.
getMergeBase gained an errNoMergeBase sentinel so exit-1 ("no common
ancestor") is distinguishable from a real git failure and can route to
the disconnected-replay path instead of bubbling up as an error.
Regression tests under FetchMetadataBranch cover the diverged and
disconnected cases and assert that the local-only checkpoint blob is
still in the tree after the fetch.
Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
Entire-Checkpoint: dbd08bd2b081
Signed-off-by: Paulo Gomes <pjbgf@linux.com> Entire-Checkpoint: 4fac0fa5ffd3
Entire-Checkpoint: 5a8ec3220416
Entire-Checkpoint: ea9e84b73618
Entire-Checkpoint: 223430e2c9ab
Entire-Checkpoint: 8f8c7f0a73c4
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://entire.io/gh/entireio/cli/trails/414
SafelyAdvanceLocalRefonly short-circuited when local was equal to or strictly ahead oftargetHash; every other state (missing, behind, diverged, disconnected) flowed into the sameSetReferencecall.That was correct for "missing" (initialize) and "behind" (fast-forward), because targetHash already contains everything reachable from local. It was wrong for the diverged and disconnected cases: local-only checkpoint commits that hadn't been pushed yet were left as orphans the moment any caller (resume, doctor, the read-side metadata fetch) advanced the local ref to a remote tip that didn't contain them.
Split the post-equality branch on git-merge-base instead:
The fast-forward path still goes through the same
setRefHashcall as before, so the existing "behind" behavior is preserved by construction. The diverged and disconnected paths now replay local-only commits onto targetHash viacherryPickOnto, which preserves the original Author and stamps the local user as Committer.getMergeBase gained an errNoMergeBase sentinel so exit-1 ("no common ancestor") is distinguishable from a real git failure and can route to the disconnected-replay path instead of bubbling up as an error.
Regression tests under
FetchMetadataBranchcover the diverged and disconnected cases and assert that the local-only checkpoint blob is still in the tree after the fetch.Note
Medium Risk
Changes how local refs are advanced during checkpoint metadata fetches by cherry-picking local-only commits onto fetched tips, which affects git history manipulation and could mis-handle edge cases in unusual repo states.
Overview
Prevents
FetchMetadataBranchfrom orphaning unpushed local checkpoints when the local metadata branch is diverged or disconnected from the fetched remote tip.SafelyAdvanceLocalRefis updated to compute a merge-base with the fetched target and, when necessary, replay local-only commits onto the fetched tip (viacherryPickOnto) instead of overwriting the ref; it also adds aerrNoMergeBasesentinel and teachesgetMergeBaseto surface the "no common ancestor" case distinctly.Adds regression tests covering diverged and disconnected fetch scenarios, asserting that local-only checkpoint blobs remain present after fetch and that the resulting branch tip reflects a replay onto the remote tip.
Reviewed by Cursor Bugbot for commit e07f383. Configure here.