version

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	*semver.Version        // Major(), Minor(), Patch(), Prerelease(), etc.
	Commits         int    // commits ahead of the tagged commit (0 = exact tag)
	Hash            string // short (7-char) SHA of HEAD
	Dirty           bool   // true if the working tree has uncommitted changes
}

Version wraps a parsed semver tag with additional git state.

func GetVersion

func GetVersion(repoPath string) (Version, error)

GetVersion opens the git repository at repoPath (pass "." for the current working directory) and returns a Version derived from the most recent semver-compatible tag reachable from HEAD.

DetectDotGit is enabled, so repoPath can be any subdirectory of the repo.

func (Version) IsExact

func (v Version) IsExact() bool

IsExact returns true when HEAD sits exactly on the tagged commit and the working tree has no uncommitted changes. Useful as a release gate.

func (Version) RCString

func (v Version) RCString() string

RCString returns the version in vM.m.(p+1)+rcN form when commits have been made since the last tag. On an exact clean tag it is identical to String(). On a dirty-only working tree (no new commits) it returns the tag with a +dirty suffix without bumping the patch — there is no meaningful rc count.

func (Version) String

func (v Version) String() string

String returns a semver-compatible string. When the repo is exactly on a tag and clean it is identical to the raw tag (e.g. "1.2.3"). Otherwise build metadata is appended:

1.2.3+4.gabcdef0        – 4 commits ahead, clean
1.2.3+4.gabcdef0.dirty  – 4 commits ahead, dirty working tree
1.2.3+dirty             – exactly on tag but dirty

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL