Artifact 394636a421b87394d20a34b710dafa3fc654b41a3b19913e079a1f27ebf26590:
- File
repo_submanifest_test.go
— part of check-in
[0ebee94560]
at
2026-10-18 16:58:56
on branch feat/submanifest-reader
— feat: sub-manifest settings in the Repo API and the CLI
Repo.EnableSubmanifests(k) now selects over the newest check-in itself, so callers pass only k (0 to select); Repo.DisableSubmanifests joins RetuneSubmanifests. `libfossil repo submanifests enable [--k N]`, `retune --k N` and `disable` drive them, printing the pin and the operator warning. The libfossil and cli SDK reference pages are regenerated. (user: [email protected], size: 2872) [annotate] [blame] [check-ins using]
package libfossil import ( "path/filepath" "strings" "testing" "time" fsltype "github.com/danmestas/go-libfossil/internal/fsltype" "github.com/danmestas/go-libfossil/internal/manifest" _ "github.com/danmestas/go-libfossil/internal/testdriver" ) // EnableSubmanifests pins k, turns emission on and hands back the operator // warning; later commits are trees, and RetuneSubmanifests moves the pin. func TestEnableSubmanifestsWritesTrees(t *testing.T) { r, err := Create(filepath.Join(t.TempDir(), "t.fossil"), CreateOpts{User: "u"}) if err != nil { t.Fatal(err) } defer r.Close() files := []FileToCommit{ {Name: "README.md", Content: []byte("# Example\n")}, {Name: "src/main.c", Content: []byte("int main(void){return 0;}\n")}, {Name: "src/node11.c", Content: []byte("/* node11 */\n")}, {Name: "src/util.c", Content: []byte("/* util */\n")}, } at := time.Date(2026, 7, 26, 0, 0, 0, 0, time.UTC) first, _, err := r.Commit(CommitOpts{Files: files, Comment: "flat", User: "u", Time: at}) if err != nil { t.Fatal(err) } if _, _, err := r.EnableSubmanifests(13); err == nil { t.Fatal("k 13 accepted") } k, warning, err := r.EnableSubmanifests(0) if err != nil || k != 1 || !strings.Contains(warning, "Fossil 2.29") { t.Fatalf("EnableSubmanifests = %d, %q, %v", k, warning, err) } if err := r.RetuneSubmanifests(3); err != nil { t.Fatal(err) } second, _, err := r.Commit(CommitOpts{Files: files[:1], Comment: "tree", User: "u", Time: at.Add(time.Hour), ParentID: first}) if err != nil { t.Fatal(err) } d, err := manifest.GetManifest(r.Inner(), fsltype.FslID(second)) if err != nil { t.Fatal(err) } if len(d.S) != 2 || len(d.F) != 0 { t.Fatalf("second commit: %d S cards, %d F cards", len(d.S), len(d.F)) } note, err := r.DisableSubmanifests() if err != nil || !strings.Contains(note, "cannot retire") { t.Fatalf("DisableSubmanifests = %q, %v", note, err) } third, _, err := r.Commit(CommitOpts{Files: files[:1], Comment: "flat again", User: "u", Time: at.Add(2 * time.Hour), ParentID: second}) if err != nil { t.Fatal(err) } if d, err := manifest.GetManifest(r.Inner(), fsltype.FslID(third)); err != nil || len(d.S) != 0 { t.Fatalf("a tree after DisableSubmanifests (%v)", err) } } // With no check-in there is nothing to select from, and the refusal leaves // emission off. func TestEnableSubmanifestsWithoutHistory(t *testing.T) { r, err := Create(filepath.Join(t.TempDir(), "t.fossil"), CreateOpts{User: "u"}) if err != nil { t.Fatal(err) } defer r.Close() if _, _, err := r.EnableSubmanifests(0); err == nil { t.Fatal("selection over no check-in succeeded") } if v, _ := r.Config("enable-submanifests"); v != "" { t.Fatalf("enable-submanifests = %q after a refusal", v) } if k, _, err := r.EnableSubmanifests(4); err != nil || k != 4 { t.Fatalf("explicit k = %d, %v", k, err) } }