Artifact 89a5929981e159cd4ae7766ccdcc8e8b334fd3468a73dba19f40a74620a638f9:
- File
internal/checkout/fork_test.go
— part of check-in
[f5744359d3]
at
2026-04-19 16:30:54
on branch trunk
— Initial open source release
libfossil is a pure-Go implementation of the Fossil SCM, reading and writing the same .fossil SQLite repository format as upstream Fossil.
This is the first public release of code that previously lived in a private repository. The module path is github.com/danmestas/libfossil and the binary is named libfossil to avoid $PATH collisions with upstream fossil.
Included: - Repo lifecycle (create, clone), checkout/checkin, timeline, merge, diff, annotate, shun, tag, branch, bisect, stash, undo/redo - Sync-over-HTTP protocol (client and handler) - Two SQLite drivers: modernc (pure Go, default) and ncruces (wasm-capable) - Observer interfaces (SyncObserver, CheckoutObserver) with an optional OpenTelemetry implementation in observer/otel (separate submodule) - Deterministic simulation testing harness with BUGGIFY fault injection - Kong-based embeddable CLI under cli/ and a standalone binary under cmd/libfossil/ (user: [email protected], size: 2912) [annotate] [blame] [check-ins using]
package checkout import ( "testing" _ "github.com/danmestas/libfossil/internal/testdriver" ) func TestBranchLeaves_SingleLeaf(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() leaves, err := BranchLeaves(r, "trunk") if err != nil { t.Fatalf("BranchLeaves: %v", err) } if len(leaves) != 1 { t.Fatalf("got %d leaves, want 1", len(leaves)) } } func TestBranchLeaves_Empty(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() leaves, err := BranchLeaves(r, "nonexistent-branch") if err != nil { t.Fatalf("BranchLeaves: %v", err) } if len(leaves) != 0 { t.Fatalf("got %d leaves, want 0", len(leaves)) } } func TestWouldFork_SingleLeaf(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() dir := t.TempDir() co, err := Create(r, dir, CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } defer co.Close() forked, err := co.WouldFork() if err != nil { t.Fatalf("WouldFork: %v", err) } if forked { t.Fatal("WouldFork = true, want false (single leaf)") } } func TestWouldFork_TrunkNoSymTag(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() dir := t.TempDir() co, err := Create(r, dir, CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } defer co.Close() rid1, _, _ := co.Version() if err := co.Extract(rid1, ExtractOpts{}); err != nil { t.Fatalf("Extract: %v", err) } co.env.Storage.WriteFile(co.dir+"/fork.txt", []byte("fork"), 0644) _, _, err = co.Commit(CommitOpts{Message: "second commit", User: "test"}) if err != nil { t.Fatalf("Commit: %v", err) } // Manually re-insert the original commit as a leaf to simulate a fork. _, err = r.DB().Exec("INSERT OR IGNORE INTO leaf(rid) VALUES(?)", int64(rid1)) if err != nil { t.Fatalf("insert leaf: %v", err) } forked, err := co.WouldFork() if err != nil { t.Fatalf("WouldFork: %v", err) } if !forked { t.Fatal("WouldFork = false, want true (trunk fork without sym-trunk tag)") } } func TestWouldFork_DifferentBranch(t *testing.T) { r, cleanup := newTestRepoWithCheckin(t) defer cleanup() dir := t.TempDir() co, err := Create(r, dir, CreateOpts{}) if err != nil { t.Fatalf("Create: %v", err) } defer co.Close() rid1, _, _ := co.Version() if err := co.Extract(rid1, ExtractOpts{}); err != nil { t.Fatalf("Extract: %v", err) } co.env.Storage.WriteFile(co.dir+"/b.txt", []byte("branch"), 0644) _, _, err = co.Commit(CommitOpts{ Message: "branch commit", User: "test", Branch: "feature-x", }) if err != nil { t.Fatalf("Commit: %v", err) } _, err = r.DB().Exec("INSERT OR IGNORE INTO leaf(rid) VALUES(?)", int64(rid1)) if err != nil { t.Fatalf("insert leaf: %v", err) } forked, err := co.WouldFork() if err != nil { t.Fatalf("WouldFork: %v", err) } if forked { t.Fatal("WouldFork = true, want false (other leaf is on different branch)") } }