checkpoint: add Push and PrimaryFetchableFromOrigin · Entire

checkpoint: add Push and PrimaryFetchableFromOrigin

12dee14→main·

pfleidi·1mo ago·2 files·+44 added/-14 removed

Push lists the refs that get pushed to the user's remote. PrimaryFetchableFromOrigin reports whether Primary appears in Push — the gate for "origin tracks this ref." Both topologies populate Push with the v1 branch.

Sessions

1aedaa7de94bView transcript

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

Changes

2

1 unmodified line

2
3
4
5
6
7
8
3 unmodified lines

12
13
14
14
15
16
17
18
15
16
20
21
22
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
9 unmodified lines

45
46
47
43
48
49
50
51
52
53
54
55

1 unmodified line

import (
    "context"
    "slices"

"github.com/go-git/go-git/v6/plumbing"

3 unmodified lines

// CommittedRefs is the committed-metadata ref topology for the active
// checkpoints_version. Resolve it once and consult it instead of re-deriving
// the topology at each read/write/mirror site.
//
// Today Primary is always the v1 branch. Opting into checkpoints_version "1.1"
// points Read and Mirror at the local-only v1.1 custom ref. A future rollout
// phase can flip the topology (v1.1 as Primary) by changing ResolveCommittedRefs.
// the topology at each read/write/mirror/push/fetch site.
type CommittedRefs struct {
    Primary plumbing.ReferenceName // source of truth: written first, pushed/fetched
    Read    plumbing.ReferenceName // committed reads resolve against this
    Mirror  plumbing.ReferenceName // advanced to Primary after v1 writes/fetches; empty = none (local-only, never pushed)
    Primary plumbing.ReferenceName   // source of truth: written and pushed
    Read    plumbing.ReferenceName   // committed reads resolve against this
    Mirror  plumbing.ReferenceName   // advanced after Primary writes/fetches; "" disables
    Push    []plumbing.ReferenceName // refs PrePush advances on the user's remote
}

// HasMirror reports whether a mirror ref is configured.
func (r CommittedRefs) HasMirror() bool { return r.Mirror != "" }

// PrimaryFetchableFromOrigin reports whether Primary has an origin-tracking
// shadow — i.e. whether bootstrap-from-origin paths can fetch it. True when
// Primary appears in Push: we push it, so origin tracks it.
func (r CommittedRefs) PrimaryFetchableFromOrigin() bool {
    return slices.Contains(r.Push, r.Primary)
}

// ResolveCommittedRefs returns the topology for the settings on disk, falling
// back to v1-branch-only when settings cannot be loaded.
func ResolveCommittedRefs(ctx context.Context) CommittedRefs {
9 unmodified lines

func committedRefsFor(mirrorEnabled bool) CommittedRefs {
    v1Branch := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
    refs := CommittedRefs{Primary: v1Branch, Read: v1Branch}
    refs := CommittedRefs{
        Primary: v1Branch,
        Read:    v1Branch,
        Push:    []plumbing.ReferenceName{v1Branch},
    }
    if mirrorEnabled {
        custom := plumbing.ReferenceName(paths.MetadataRefName)
        refs.Read = custom

Mcmd/entire/cli/checkpoint/committed_refs.go+18/-9


3 unmodified lines

4
5
6
7
8
9
10
11 unmodified lines

22
23
24
24
25
25
26
27
28
29
16 unmodified lines

46
47
48
48
49
50
49
50
51
52
53
54
2 unmodified lines

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

3 unmodified lines

"context"
    "testing"

"github.com/go-git/go-git/v6/plumbing"
    "github.com/stretchr/testify/assert"

"github.com/entireio/cli/cmd/entire/cli/settings"
11 unmodified lines

version string // checkpoints_version value; "" omits it
    want    CommittedRefs
    }{
        {"unset", "", CommittedRefs{Primary: v1, Read: v1}},
        {"opted in", `"1.1"`, CommittedRefs{Primary: v1, Read: custom, Mirror: custom}},
        {"unset", "", CommittedRefs{Primary: v1, Read: v1, Push: []plumbing.ReferenceName{v1}}},
        {"opted in", `"1.1"`, CommittedRefs{Primary: v1, Read: custom, Mirror: custom, Push: []plumbing.ReferenceName{v1}}},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
16 unmodified lines

settings *settings.EntireSettings
    want     CommittedRefs
    }{
        {"nil", nil, CommittedRefs{Primary: v1, Read: v1}},
        {"empty", &settings.EntireSettings{}, CommittedRefs{Primary: v1, Read: v1}},
        {"opted in", version("1.1"), CommittedRefs{Primary: v1, Read: custom, Mirror: custom}},
        {"nil", nil, CommittedRefs{Primary: v1, Read: v1, Push: []plumbing.ReferenceName{v1}}},
        {"empty", &settings.EntireSettings{}, CommittedRefs{Primary: v1, Read: v1, Push: []plumbing.ReferenceName{v1}}},
        {"opted in", version("1.1"), CommittedRefs{Primary: v1, Read: custom, Mirror: custom, Push: []plumbing.ReferenceName{v1}}},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
2 unmodified lines

})
    }
}

func TestCommittedRefs_PrimaryFetchableFromOrigin(t *testing.T) {
    t.Parallel()
    v1, custom := v1BranchRef(), customRef()
    tests := []struct {
        name string
        refs CommittedRefs
        want bool
    }{
        {"v1 in push", CommittedRefs{Primary: v1, Push: []plumbing.ReferenceName{v1}}, true},
        {"primary not in push", CommittedRefs{Primary: custom, Push: []plumbing.ReferenceName{v1}}, false},
        {"empty push", CommittedRefs{Primary: v1, Push: nil}, false},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
                t.Parallel()
            assert.Equal(t, tt.want, tt.refs.PrimaryFetchableFromOrigin())
        })
    }
}