Skip to content
internal/gitversion
On this page

Holds the per-feature git version floors, so a command needing a newer git refuses by name and says what to upgrade to, instead of a raw error from git.

#internal/gitversion

#internal/gitversion

Package gitversion parses the installed git's version and compares it against the per-feature floors safegit depends on.

Every git capability safegit uses that is not ancient is declared here as a Feature with the git version that introduced it. A command that needs one calls Require, which produces an error naming both the feature and its floor, so an operator on an older git is told what to upgrade to and why -- never handed a raw "unknown option" from git.

#MergeTreeWriteTree

Go go
var MergeTreeWriteTree = Feature{

MergeTreeWriteTree is the real merge engine: computing a merge into an object store without touching the index or the worktree.

#AttrSource

Go go
var AttrSource = Feature{

AttrSource lets attribute lookups come from a tree instead of the worktree, which is what makes a worktree-free merge honor .gitattributes.

#MergeTreeStrategyOption

Go go
var MergeTreeStrategyOption = Feature{

MergeTreeStrategyOption is -X on the merge engine: tuning how the merge resolves, the way git merge -X does. git's own release note for it reads "git merge-tree" learned to take strategy backend specific options via the "-X" option, like "git merge" does.

#Version

Go go
type Version struct

Version is a git version, compared major-then-minor-then-patch. Trailing vendor suffixes git appends on some platforms ("2.39.5 (Apple Git-154)", "2.42.0.windows.2") are not part of the ordering.

#Feature

Go go
type Feature struct

Feature is a git capability with the version that introduced it.

#Parse

Go go
func Parse(s string) (Version, error)

Parse reads a version out of git --version output ("git version 2.43.0") or a bare version string ("2.43.0", "2.39"). An absent patch component reads as 0. Anything after the numeric components is ignored, so vendor suffixes do not make a version unparseable.

#Features

Go go
func Features() []Feature

Features returns every declared feature floor.

#HighestFloor

Go go
func HighestFloor() Feature

HighestFloor returns the feature with the newest floor: the git version that makes every safegit feature available.

#Require

Go go
func Require(have Version, f Feature) error

Require returns nil when have satisfies f's floor, and an error naming the feature, the floor and the version actually found otherwise.

#Version.String

Go go
func (v Version) String() string

#Version.Compare

Go go
func (v Version) Compare(o Version) int

Compare returns -1, 0 or 1 as v sorts before, equal to, or after o.

#Version.AtLeast

Go go
func (v Version) AtLeast(o Version) bool { return v.Compare(o) >= 0 }

AtLeast reports whether v is o or newer.

#Version.Before

Go go
func (v Version) Before(o Version) bool { return v.Compare(o) < 0 }

Before reports whether v is older than o.

Search