Artifact 3296f9fb36ea11da612a5195ec6a42ceb1082adefac360c9f7d01e11fc729fbf:
- File
cli/repo_co.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: 1537) [annotate] [blame] [check-ins using]
package cli import ( "fmt" "os" "path/filepath" "github.com/danmestas/libfossil/internal/blob" "github.com/danmestas/libfossil/internal/content" ) // RepoCoCmd checks out a version to the working directory. type RepoCoCmd struct { Version string `arg:"" optional:"" help:"Version to checkout (default: tip)"` Dir string `short:"d" help:"Output directory (default: current dir)" default:"."` Force bool `help:"Overwrite existing files"` } func (c *RepoCoCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() rid, err := resolveRID(r, c.Version) if err != nil { return err } files, err := r.ListFiles(rid) if err != nil { return err } db := r.Inner().DB() for _, f := range files { fileRid, ok := blob.Exists(db, f.UUID) if !ok { return fmt.Errorf("blob %s not found for file %s", f.UUID, f.Name) } data, err := content.Expand(db, fileRid) if err != nil { return fmt.Errorf("expanding %s: %w", f.Name, err) } outPath := filepath.Join(c.Dir, f.Name) if err := os.MkdirAll(filepath.Dir(outPath), 0o755); err != nil { return err } if !c.Force { if _, err := os.Stat(outPath); err == nil { return fmt.Errorf("file exists: %s (use --force to overwrite)", outPath) } } perm := os.FileMode(0o644) if f.Perm == "x" { perm = 0o755 } if err := os.WriteFile(outPath, data, perm); err != nil { return err } fmt.Printf(" %s\n", f.Name) } fmt.Printf("checked out %d files\n", len(files)) return nil }