Documentation
¶
Overview ¶
Package history reads a repository and produces exactly what a version decision needs: where the project is now, and what has landed since.
This is the seam where I/O enters. Everything above it — package policy — is pure, which is what makes the decision testable as a table and reviewable without running anything. Keeping the git in one narrow place is what buys that.
Index ¶
Constants ¶
const FirstVersion = "0.0.0"
FirstVersion is where a project with no releases starts.
A repository with no semver tag has no current version, so one has to be chosen rather than discovered. 0.0.0 is the choice, which means the first release is decided by its commits exactly as every later one is: a feat makes it 0.1.0, a fix makes it 0.0.1.
The alternative — defaulting the first release to 0.1.0 whatever landed — was rejected because it makes the first release the one release whose number nobody can explain from the log.
Variables ¶
var ( // ErrTagNotFound reports a release tag the repository does not carry. ErrTagNotFound = errors.New("release tag not found") // ErrNotAVersion reports a tag that does not name a semantic version. ErrNotAVersion = errors.New("tag is not a version") // ErrNotAtTag reports a checkout whose HEAD is not the tagged commit. The // commits are walked from HEAD, so anywhere else would describe a // different release from the one named. ErrNotAtTag = errors.New("HEAD is not at the release tag") )
var ErrAmbiguousLatest = errors.New("ambiguous latest release")
ErrAmbiguousLatest reports two reachable tags that compare equal under semver precedence but exclude different commits — "v1.0.0+a" and "v1.0.0+b". There is no highest, and choosing one silently changes what the release contains.
var ErrNoComponent = errors.New("no component")
ErrNoComponent reports a ReadComponent call with nothing to read.
var ErrNotARepository = errors.New("not a git repository")
ErrNotARepository reports a path that is not a git repository.
var ErrShallowClone = errors.New("this checkout is shallow (depth-limited clone)")
ErrShallowClone reports a depth-limited checkout. Whether such a clone holds enough history to answer correctly changes with every commit that lands, so it is refused before the walk rather than after the walk happens to fail.
var ErrUnresolvableHEAD = errors.New("HEAD cannot be resolved")
ErrUnresolvableHEAD reports a repository that has history its HEAD cannot reach. Reporting it as empty would compute a release from thin air.
Functions ¶
Types ¶
type Component ¶ added in v0.5.0
Component is what history needs to read a directory with a version of its own (spec 0010 D2). TagPrefix is the component's tag template rendered with an empty version: "lint/v" for the default shape, "capabilitygen-v" for a `{name}-v{version}` template. Every tag it writes ends in the version, so the prefix is the whole rule.
type Option ¶ added in v0.5.0
type Option func(*scope)
Option narrows what Read considers.
type Range ¶
type Range struct {
// Dir is the component's directory, empty for the root (spec 0010 D2).
Dir string
// Root is the repository's working-tree root, resolved by walking up from
// the supplied path.
//
// Anything else read per-repository — the manifest above all — must use
// this rather than the path the caller happened to pass, or `plan -C
// ./subdir` reads the same history with the manifest silently missing.
Root string
// Current is the latest released version, or FirstVersion when there are
// none.
Current semver.Version
// FromTag is the tag Current came from. Empty when the project has never
// released, which is what distinguishes "no releases" from "released 0.0.0".
FromTag string
// Commits are those not yet in any release, newest first.
Commits []policy.Commit
}
Range is a repository reduced to what a decision needs.
func ReadComponent ¶ added in v0.5.0
ReadComponent reduces one component to a Range: its current version is the highest reachable tag carrying its prefix, and its commits are those since that tag whose diff touches its directory.
The same walk as the root's, with the tag rule and the path filter swapped: the root refuses any tag with a slash and reads everything outside the components; a component reads only tags with its prefix and only the commits under it. Neither can read the other's tags, because the manifest refuses a template the root could read and refuses two that render alike.
func (Range) HasReleased ¶
HasReleased reports whether the project has ever cut a release.
type Released ¶ added in v0.3.0
Released is one named release and the range of history it covers.
Current and FromTag describe the release BEFORE this one, and Commits are what this release added on top of it: the same shape Read gives for a release that has not happened yet, for a release that has.
func ReadComponentRelease ¶ added in v0.5.0
ReadComponentRelease is ReadRelease for a component's tag: the previous release is the highest reachable tag with the component's prefix strictly below this one, and the commits are those between that touch its directory (spec 0011 D4, on spec 0010 D2).
func ReadRelease ¶ added in v0.3.0
ReadRelease reduces the repository at path to the range a named release covers: from the highest reachable semver tag strictly below it, to the tagged commit. HEAD must be that commit.
Spec 0005 D4. Strictly below, because on a checkout of the tag the highest reachable tag is the tag itself and the range would be empty. The ambiguity refusal is inherited from Read for the reason it exists there.