# checkpoint: route committed writes through refs.Primary

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

pfleidi·1mo ago·3 files·+37 added/-11 removed

Five write sites in committed.go and the getSessionsBranchRef helper
in parse_tree.go now use s.refs.Primary instead of the v1 branch
literal. At today's resolver Primary is the v1 branch, so behavior is
unchanged. A new test asserts the property directly: writes against a
synthetic Primary advance that ref, not v1.

## Sessions

a4f1609e268dView transcript

## Changes

3

- cmd/entire/cli/checkpoint

- Mcommitted.go+5/-5

- Mcommitted_read_store_test.go+28

- Mparse_tree.go+4/-6

```
122 unmodified lines

123
124
125
126
126
127
128
129
471 unmodified lines

601
602
603
604
604
605
606
607
825 unmodified lines

1433
1434
1435
1436
1436
1437
1438
1439
118 unmodified lines

1558
1559
1560
1561
1561
1562
1563
1564
162 unmodified lines

1727
1728
1729
1730
1730
1731
1732
1733

122 unmodified lines

return err
	}

refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	refName := s.refs.Primary
	newRef := plumbing.NewHashReference(refName, newCommitHash)
	if err := s.repo.Storer.SetReference(newRef); err != nil {
		return fmt.Errorf("failed to set branch reference: %w", err)
	}
471 unmodified lines

return err
	}

refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	refName := s.refs.Primary
	newRef := plumbing.NewHashReference(refName, newCommitHash)
	if err := s.repo.Storer.SetReference(newRef); err != nil {
		return fmt.Errorf("failed to set branch reference: %w", err)
	}
825 unmodified lines

return err
	}

refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	refName := s.refs.Primary
	newRef := plumbing.NewHashReference(refName, newCommitHash)
	if err := s.repo.Storer.SetReference(newRef); err != nil {
		return fmt.Errorf("failed to set branch reference: %w", err)
	}
118 unmodified lines

return err
	}

refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	refName := s.refs.Primary
	newRef := plumbing.NewHashReference(refName, newCommitHash)
	if err := s.repo.Storer.SetReference(newRef); err != nil {
		return fmt.Errorf("failed to set branch reference: %w", err)
	}
162 unmodified lines

// ensureSessionsBranch ensures the entire/checkpoints/v1 branch exists.
func (s *GitStore) ensureSessionsBranch(ctx context.Context) error {
	refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	refName := s.refs.Primary
	_, err := s.repo.Reference(refName, true)
	if err == nil {
		return nil // Branch exists
	}
}

Mcmd/entire/cli/checkpoint/committed.go+5/-5

```
108 unmodified lines

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

108 unmodified lines

assert.Equal(t, customRef(), NewGitStore(nil, customRefs).CommittedReadRef())

// Not parallel: WriteCommitted touches repo refs.
func TestGitStore_WriteCommittedTargetsPrimary(t *testing.T) {
	dir, repo, _ := newTestRepo(t)
	 t.Chdir(dir)

synthetic := plumbing.ReferenceName("refs/entire/checkpoints/synthetic-primary")
	refs := CommittedRefs{Primary: synthetic, Read: synthetic, Push: []plumbing.ReferenceName{synthetic}}
	store := NewGitStore(repo, refs)

cpID := id.MustCheckpointID("a1b2c3d4e5f6")
	require.NoError(t, store.WriteCommitted(context.Background(), WriteCommittedOptions{
		CheckpointID: cpID,
		SessionID: "session",
		Strategy: "manual-commit",
		Transcript: redact.AlreadyRedacted([]byte("transcript\n")),
		Prompts: []string{"prompt"},
		AuthorName: "Test",
		AuthorEmail: "test@test.com",
	}))(error)

ref, err := repo.Reference(synthetic, true)
	require.NoError(t, err, "synthetic primary ref must exist after write")
	assert.NotEqual(t, plumbing.ZeroHash, ref.Hash())

_, err = repo.Reference(v1BranchRef(), true)
	assert.ErrorIs(t, err, plumbing.ErrReferenceNotFound, "v1 branch must not be touched when Primary is synthetic")
}

func TestNewGitStore_UsesRefs(t *testing.T) {
	t.Parallel()
	dir := t.TempDir()
```

Mcmd/entire/cli/checkpoint/committed_read_store_test.go+28

```
10 unmodified lines

11
12
13
14
14
15
16
424 unmodified lines

441
442
443
445
446
444
445
446
448
449
447
448
451
449
450
451
452

10 unmodified lines

"github.com/entireio/cli/cmd/entire/cli/checkpoint/id"
	"github.com/entireio/cli/cmd/entire/cli/logging"
	"github.com/entireio/cli/cmd/entire/cli/paths"

"github.com/go-git/go-git/v6"
	"github.com/go-git/go-git/v6/plumbing"
424 unmodified lines

return parts[0], parts[1]

// getSessionsBranchRef returns the sessions branch parent commit hash and root tree hash
// without flattening the tree.
// getSessionsBranchRef returns the primary metadata ref's commit hash and root tree
// hash without flattening the tree.
func (s *GitStore) getSessionsBranchRef() (plumbing.Hash, plumbing.Hash, error) {
	refName := plumbing.NewBranchReferenceName(paths.MetadataBranchName)
	ref, err := s.repo.Reference(refName, true)
	ref, err := s.repo.Reference(s.refs.Primary, true)
	if err != nil {
		return plumbing.ZeroHash, plumbing.ZeroHash, fmt.Errorf("failed to get sessions branch reference: %w", err)
		return plumbing.ZeroHash, plumbing.ZeroHash, fmt.Errorf("failed to get primary metadata ref %s: %w", s.refs.Primary, err)
	}

parentCommit, err := s.repo.CommitObject(ref.Hash())  
}
