Artifact 9e1ca1a153a6cebebea64d18f1c7eebefcd3dd635066acf20d3d0a326ae4d5ce:
- File
cli/shared.go
— part of check-in
[6273a0750d]
at
2026-07-22 23:03:24
on branch trunk
— fix: correct go.mod module path to go-libfossil (#76) (#117)
* fix: correct go.mod module path to go-libfossil (#76)
The module directive still declared github.com/danmestas/libfossil after the repository was renamed to go-libfossil. pkg.go.dev/godoc scraping matches the declared module path against its hosting path, so the stale path broke SDK doc generation.
Rename the module path across all four in-repo modules (root, the two db/driver submodules, observer/otel, and docs/site) and every internal import, plus the release workflow, the doc-generation script, and the docs.
No tag has been published under the go-libfossil path yet, so the cross-module requires cannot resolve from the proxy. Add replace directives pointing the in-repo requires at their local directories so GOWORK=off builds and the CI matrix resolve without a published version. These replaces are ignored by downstream consumers and can be dropped once new-path tags are cut.
* Guard releases against replace directives; regenerate SDK docs
The go-libfossil rename bridges the in-repo modules with `replace` directives. Go refuses a main module that carries them, so a tag cut while they are present breaks `go install .../cmd/libfossil@<tag>` and every `@version` fetch of the driver submodules. Add a Release workflow step that fails the job before anything is published if any tracked go.mod still contains a replace directive, so the bridge is a CI-enforced TODO rather than a silent landmine. The step comment records what unblocks a release: re-tag the submodules with the corrected module paths, bump the root requires, then drop the replace blocks.
Regenerate the SDK reference docs. The previous pass only substituted URLs over the pre-existing generated files, leaving stale signatures (Repo.Timeline was still documented as taking LogOpts rather than TimelineOpts). Note that gomarkdoc must be run outside a git worktree — inside one it silently strips every source link.
Also reword the README rename note, which read as though the import path had not changed, and re-sort the ncruces require block. (user: [email protected], size: 3239) [annotate] [blame] [check-ins using]
package cli import ( "database/sql" "fmt" "os" "os/user" "path/filepath" libdb "github.com/danmestas/go-libfossil/db" libfossil "github.com/danmestas/go-libfossil" ) // Globals holds flags shared by all CLI commands. type Globals struct { Repo string `short:"R" help:"Path to repository file" type:"path"` Verbose bool `short:"v" help:"Verbose output"` } // OpenRepo opens a Fossil repository using the handle API. // If Repo is empty, it searches for a .fossil file or .fslckout checkout. func (g *Globals) OpenRepo() (*libfossil.Repo, error) { if g.Repo == "" { found, err := findRepo() if err != nil { return nil, fmt.Errorf("no repository specified (use -R <path>)") } g.Repo = found } return libfossil.Open(g.Repo) } // resolveRID resolves a version string to a rid. // Accepts: empty/"tip" (most recent checkin), "trunk" (tagged trunk tip), // named branch, UUID prefix (min 4 chars), or full UUID. // // This is a thin CLI-layer wrapper around Repo.ResolveVersion, which holds // the canonical resolution logic. func resolveRID(r *libfossil.Repo, version string) (int64, error) { return r.ResolveVersion(version) } // currentUser returns the current OS username, or "anonymous" if unavailable. func currentUser() string { if u, err := user.Current(); err == nil { return u.Username } return "anonymous" } // findRepo searches the current directory and its parents for a .fossil file // or a .fslckout checkout database that points to a repo. func findRepo() (string, error) { dir, err := os.Getwd() if err != nil { return "", err } for { ckout := filepath.Join(dir, ".fslckout") if _, err := os.Stat(ckout); err == nil { return repoFromCheckout(ckout) } matches, _ := filepath.Glob(filepath.Join(dir, "*.fossil")) if len(matches) == 1 { return matches[0], nil } parent := filepath.Dir(dir) if parent == dir { break } dir = parent } return "", fmt.Errorf("no .fossil file found") } // repoFromCheckout reads the repository path from a .fslckout database. func repoFromCheckout(ckoutPath string) (string, error) { db, err := libdb.OpenSQL(ckoutPath, libdb.OpenConfig{}, map[string]string{"mode": "ro"}) if err != nil { return "", err } defer db.Close() var repoPath string err = db.QueryRow("SELECT value FROM vvar WHERE name='repository'").Scan(&repoPath) if err != nil { return "", fmt.Errorf("checkout %s: no repository path found", ckoutPath) } return repoPath, nil } // openCheckout opens the .fslckout database in the given directory. func openCheckout(dir string) (*sql.DB, error) { ckoutPath := filepath.Join(dir, ".fslckout") if _, err := os.Stat(ckoutPath); err != nil { ckoutPath = filepath.Join(dir, "_FOSSIL_") if _, err := os.Stat(ckoutPath); err != nil { return nil, fmt.Errorf("no checkout found in %s (run 'fossil repo open' first)", dir) } } return libdb.OpenSQL(ckoutPath, libdb.OpenConfig{}, nil) } // checkoutVid returns the current checkout version ID from vvar. func checkoutVid(db *sql.DB) (int64, error) { var vid int64 err := db.QueryRow("SELECT value FROM vvar WHERE name='checkout'").Scan(&vid) if err != nil { return 0, fmt.Errorf("reading checkout version: %w", err) } return vid, nil }