@@ -464,6 +464,17 @@ func resolveAgentType(ctxAgentType types.AgentType, state *SessionState) types.A
464464// origin holds the store — when Primary is in Push and the local ref is missing
465465// or un-initialized, the local ref is created/updated from origin's
466466// remote-tracking ref. Otherwise an empty orphan is created.
467+ // primaryIsGitRefs reports whether the configured primary checkpoint backend is
468+ // git-refs. Resolution is fail-soft: any config-load error is treated as the
469+ // default git-branch backend (returns false), preserving legacy behavior.
470+ func primaryIsGitRefs (ctx context.Context ) bool {
471+ cfg , err := settings .LoadCheckpointsConfig (ctx )
472+ if err != nil {
473+ return false
474+ }
475+ return checkpoint .PrimaryIsRefs (cfg )
476+ }
477+
467478func EnsurePrimaryRef (ctx context.Context , repo * git.Repository ) error {
468479 // Rebind settings/remote resolution to the repository being modified rather
469480 // than the ambient working directory, so the "is a checkpoint_remote
@@ -477,6 +488,17 @@ func EnsurePrimaryRef(ctx context.Context, repo *git.Repository) error {
477488 refs := checkpoint .ResolveRefs (ctx )
478489 primaryName := refs .Primary .Short ()
479490
491+ // Under the git-refs primary backend, checkpoints are written to
492+ // per-checkpoint refs and nothing is ever written to the v1 metadata
493+ // branch. Seeding an empty orphan v1 here would leave a vestigial,
494+ // never-written branch — the surprise a user hit when `entire enable`
495+ // selected git-refs yet still created entire/checkpoints/v1. We still adopt
496+ // real v1 data that already exists on origin or a checkpoint_remote below
497+ // (so legacy checkpoints stay readable); we only suppress the empty-orphan
498+ // fallback. Resolution is fail-soft: an unreadable config keeps the legacy
499+ // git-branch seeding behavior.
500+ skipEmptyOrphan := primaryIsGitRefs (ctx )
501+
480502 localRef , localErr := repo .Reference (refs .Primary , true )
481503 if localErr != nil && ! errors .Is (localErr , plumbing .ErrReferenceNotFound ) {
482504 return fmt .Errorf ("failed to check metadata ref: %w" , localErr )
@@ -515,6 +537,9 @@ func EnsurePrimaryRef(ctx context.Context, repo *git.Repository) error {
515537 // Nothing usable on the checkpoint remote (fetch skipped/failed or the
516538 // remote has no data) — create a fresh orphan that future pushes publish
517539 // there. Still never origin.
540+ if skipEmptyOrphan {
541+ return nil
542+ }
518543 return createOrphanMetadataRef (ctx , repo , refs )
519544 }
520545
@@ -565,6 +590,9 @@ func EnsurePrimaryRef(ctx context.Context, repo *git.Repository) error {
565590 }
566591
567592 // No local or origin ref — create an empty orphan.
593+ if skipEmptyOrphan {
594+ return nil
595+ }
568596 return createOrphanMetadataRef (ctx , repo , refs )
569597}
570598
0 commit comments