Artifact b2e334708ccf0e7c2a3d88ed2b252f299c08eb460f7da22a2f94ee99047350ad:
- File
cli/repo_ci.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: 1667) [annotate] [blame] [check-ins using]
package cli import ( "fmt" "os" "path/filepath" "time" libfossil "github.com/danmestas/libfossil" ) // RepoCiCmd creates a new checkin (commit). type RepoCiCmd struct { Message string `short:"m" required:"" help:"Checkin comment"` Files []string `arg:"" required:"" help:"Files to checkin"` User string `help:"Checkin user (default: OS username)"` Parent string `help:"Parent version UUID (default: tip)"` Branch string `help:"Branch name for this checkin"` } func (c *RepoCiCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() var parentRid int64 if c.Parent != "" { parentRid, err = resolveRID(r, c.Parent) if err != nil { return fmt.Errorf("resolving parent: %w", err) } } else { parentRid, _ = resolveRID(r, "") // ignore error for initial checkin } files := make([]libfossil.FileToCommit, len(c.Files)) for i, path := range c.Files { data, err := os.ReadFile(path) if err != nil { return fmt.Errorf("reading %s: %w", path, err) } files[i] = libfossil.FileToCommit{ Name: filepath.Base(path), Content: data, } } user := c.User if user == "" { user = currentUser() } var tags []libfossil.TagSpec if c.Branch != "" { tags = append(tags, libfossil.TagSpec{Name: "branch", Value: c.Branch}, libfossil.TagSpec{Name: "sym-" + c.Branch}, ) } rid, uuid, err := r.Commit(libfossil.CommitOpts{ Files: files, Comment: c.Message, User: user, ParentID: parentRid, Time: time.Now().UTC(), Tags: tags, }) if err != nil { return err } fmt.Printf("checkin %s (rid=%d)\n", uuid[:10], rid) return nil }