Documentation
¶
Overview ¶
Package baseline resolves and materializes a git revision into a tempdir so `flate diff` can run without an explicit --path-orig.
The user-facing flow: when --path-orig isn't supplied, the CLI asks baseline.Resolve for the commit to diff against (either the explicit --base=<rev>, or auto-detected via merge-base with the branch's upstream / origin/HEAD / origin/{main,master}) and then asks Materialize to extract that commit's tree into a fresh tempdir. The CLI sets --path-orig to that tempdir for the remainder of the diff run, then deletes it on exit.
This package treats the user's checkout as read-only — it opens the existing repo via go-git's object store and does not mutate the working tree, the index, or refs. The materialized tempdir is the only side effect, and it lives only for the diff invocation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GitRepoRoot ¶
GitRepoRoot returns the .git ancestor of path, or "" when none exists. Exposed so callers can branch on "is this a git repo" before calling AutoResolve. Renamed from FindRepoRoot to disambiguate from `discovery.FindRepoRoot` which has different fallback semantics (returns p unchanged when no .git exists, rather than "").
Types ¶
type Result ¶
type Result struct {
// PathOrig is the path the caller should use as the synthetic
// --path-orig: <TempDir>/<rel> where rel is the user's --path
// relative to the git repo root.
PathOrig string
// TempDir is the root of the materialized tree. When Persistent
// is false, caller is responsible for os.RemoveAll once the diff
// is done. When Persistent is true, the directory lives under the
// cache root and is meant to be reused across runs — caller MUST
// NOT remove it.
TempDir string
// Persistent reports whether TempDir lives under a content-
// addressed cache root (and so survives across runs) or is a
// disposable MkdirTemp directory (legacy behavior). Callers wire
// cleanup conditionally on this flag.
Persistent bool
// Rev is the resolved short SHA of the baseline commit, for
// logging and error context.
Rev string
// Source is a human-readable description of how the rev was
// picked (e.g. "merge-base with origin/HEAD", "explicit
// --base=main"), surfaced in the startup log line.
Source string
// SelfURLs are the working tree's git remote URLs (raw, unnormalized).
// The materialized baseline tree carries no .git, so the caller passes
// these to the baseline render as Config.SelfURLs — the source root
// represents the same repo, so a self-referential GitRepository aliases
// to the local tree on the baseline side too.
SelfURLs []string
}
Result describes a materialized baseline tree on disk.
func AutoResolve ¶
AutoResolve picks a baseline for path, materializes it, and returns a Result with the synthetic --path-orig already mapped into the baseline tree's coordinate system. When base is non-empty it is the explicit --base=<rev> override; otherwise the auto-detection ladder runs.
layout enables content-addressed reuse: when layout.Root is non- empty the baseline lands at layout.Baseline(commitSHA) and Result is marked Persistent — subsequent runs against the same commit skip materialization entirely. When layout.Root is "" the legacy MkdirTemp path runs and the caller is responsible for cleanup.
Errors carry the suggested next flag so the user knows whether to pass --base=<rev> or --path-orig=<dir>.