# strategy: extract AdvanceCommittedPrimary helper

`1a2296b`→[main](/content/gh/entireio/cli/commits/main/index.html)·

pfleidi·1mo ago·10 files·+116 added/-54 removed

AdvanceCommittedPrimary sets refs.Primary to hash and best-effort
advances refs.Mirror. Replaces (SetReference + MirrorBestEffort) pairs
across EnsureMetadataBranch, metadata_reconcile, cleanup, condensation,
attribution, finalization, and the post-fetch mirror site. The
best-effort mirror wrapper becomes unexported and takes refs
explicitly. MirrorCommittedMetadataRef (strict) stays exported for
attach and explain summary writes, where surfacing failure is more
useful than silent best-effort.

## Sessions

7ab1391b8aadView transcript

[?\
Streamline Checkpoint Version Mirroring with refs.PrimaryClaude Code·1 step](/content/gh/entireio/cli/session/7d8b9a47-6f94-441b-adae-5402ded54425#timeline-7ab1391b8aad/index.html)

## Changes

10

- cmd/entire/cli

- Mgit_operations.go+5/-1

- strategy

- Mcheckpoint_remote.go+1/-1

- Mcleanup.go+2/-4

- Mcommon.go+4/-9

- Mmanual_commit_condensation.go+3/-3

- Mmanual_commit_hooks.go+6/-6

- Mmetadata_reconcile.go+3/-7

- Mpush_common.go+1/-1

- Mv1_custom_ref_mirror.go+25/-18

- Mv1_custom_ref_mirror_test.go+66/-4

```go
471 unmodified lines

if err := strategy.SafelyAdvanceLocalRef(ctx, repo, refs.Primary, remoteRef.Hash()); err != nil {
    return fmt.Errorf("failed to advance local %s branch: %w", branchName, err)
}
strategy.MirrorCommittedMetadataRefBestEffort(ctx, repo)
if err := strategy.MirrorCommittedMetadataRef(ctx, repo, refs); err != nil && !errors.Is(err, strategy.ErrPrimaryMetadataMissing) {
    logging.Warn(ctx, "committed-ref mirror failed after origin fetch",
        slog.String("ref", refs.Mirror.String()),
        slog.String("error", err.Error()))
}
return nil
}
```

Mcmd/entire/cli/git_operations.go+5/-1

```go
124 unmodified lines

defer repo.Close()
MirrorCommittedMetadataRefBestEffort(ctx, repo)
mirrorCommittedMetadataRefBestEffort(ctx, repo, refs)
return nil
}
```

Mcmd/entire/cli/strategy/checkpoint_remote.go+1/-1

```go
333 unmodified lines

// Update branch reference
    newRef := plumbing.NewHashReference(refName, commitHash)
    if err := repo.Storer.SetReference(newRef); err != nil {
      // Update branch reference and best-effort mirror
      if err := AdvanceCommittedPrimary(ctx, repo, checkpoint.ResolveCommittedRefs(ctx), commitHash); err != nil {
        return nil, nil, fmt.Errorf("failed to update branch: %w", err)
      }
      MirrorCommittedMetadataRefBestEffort(ctx, repo)

// All checkpoints deleted successfully
    return checkpointIDs, []string{}, nil
}
```

// Further code snippets and operations would continue in this fashion.
