git

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTagFromBranch added in v1.3.0

func ExtractTagFromBranch(branchName, prefix string) (string, error)

ExtractTagFromBranch extracts the base tag from hotfix branch name. Example: "release/api/v1.0.0" with prefix "release/" → "api/v1.0.0"

func GetCurrentBranch added in v1.3.0

func GetCurrentBranch(repoDir string) (string, error)

GetCurrentBranch returns the currently checked out branch name.

func IsHotfixBranch added in v1.3.0

func IsHotfixBranch(branchName, prefix string) bool

IsHotfixBranch checks if current branch matches hotfix pattern.

func ListBranches added in v1.3.0

func ListBranches(repoDir string) ([]string, error)

ListBranches returns all branches in the repository.

func ValidateHotfixBaseTag added in v1.3.0

func ValidateHotfixBaseTag(ctx context.Context, repoDir, tag string) error

ValidateHotfixBaseTag ensures tag is valid for hotfix creation.

func ValidateWorkingTreeClean added in v1.3.0

func ValidateWorkingTreeClean(ctx context.Context, repoDir string) error

ValidateWorkingTreeClean ensures working tree is clean.

Types

type TagInfo

type TagInfo struct {
	Tag     string
	Version string
	Commit  string
	Date    string
	Message string
}

TagInfo represents information about a version tag.

type Tagger

type Tagger struct {
	// contains filtered or unexported fields
}

Tagger handles git tag operations.

func NewTagger

func NewTagger(repoDir, prefix string, dryRun bool) *Tagger

NewTagger creates a new Tagger for the given repository directory.

func (*Tagger) CalculateNextVersion

func (t *Tagger) CalculateNextVersion(
	ctx context.Context,
	scheme version.Scheme,
	bump version.BumpType,
	calverFormat, pre, meta string,
) (*version.Version, error)

CalculateNextVersion calculates the next version without creating a tag. This is useful when you need to know the version before making changes (e.g., updating package.json).

func (*Tagger) CalculatePreRelease added in v1.3.0

func (t *Tagger) CalculatePreRelease(ctx context.Context, channel, bumpType string) (*version.Version, error)

CalculatePreRelease computes the next prerelease version for a SemVer tag.

channel is the prerelease identifier (e.g., "alpha", "beta", "rc"). Pass "release" to graduate the current prerelease to a stable version. bumpType ("major", "minor", "patch") is required when the latest tag is stable and channel is not "release".

func (*Tagger) CommitVersionUpdate

func (t *Tagger) CommitVersionUpdate(ctx context.Context, filePath, version string) error

CommitVersionUpdate commits a version file update (like package.json). It stages the file, creates a commit with a standard message.

func (*Tagger) CreateHotfixBranch added in v1.3.0

func (t *Tagger) CreateHotfixBranch(ctx context.Context, tag, branchPrefix string, checkout bool) (string, error)

CreateHotfixBranch creates a new hotfix branch from specified tag.

func (*Tagger) CreateHotfixTag added in v1.3.0

func (t *Tagger) CreateHotfixTag(ctx context.Context, tag, message string) error

CreateHotfixTag creates a hotfix tag from current HEAD.

func (*Tagger) CreateNextTag

func (t *Tagger) CreateNextTag(
	ctx context.Context,
	scheme version.Scheme,
	bump version.BumpType,
	calverFormat, pre, meta string,
) (string, error)

CreateNextTag generates the next tag based on the scheme and creates it. For semver, bump is required. For calver, the current date is used.

func (*Tagger) CreateTag

func (t *Tagger) CreateTag(ctx context.Context, tag, message string) error

CreateTag creates an annotated tag with the given name and message. If dryRun is true, only logs the operation without creating the tag.

func (*Tagger) CurrentCommit

func (t *Tagger) CurrentCommit(ctx context.Context) (string, error)

CurrentCommit returns the current commit hash.

func (*Tagger) GetNextHotfixTag added in v1.3.0

func (t *Tagger) GetNextHotfixTag(ctx context.Context, baseTag, suffix string) (string, int, error)

GetNextHotfixTag determines next hotfix version from base tag. Example: base "v1.0.0", existing "v1.0.0-hotfix.2" → returns "v1.0.0-hotfix.3", seq 3

func (*Tagger) GetTagCommit added in v1.3.0

func (t *Tagger) GetTagCommit(ctx context.Context, tag string) (string, error)

GetTagCommit returns the full commit hash that the given tag points to. For annotated tags, it dereferences the tag object to the underlying commit.

func (*Tagger) GetTagInfo

func (t *Tagger) GetTagInfo(ctx context.Context, tagName string) (*TagInfo, error)

GetTagInfo retrieves detailed information for a specific tag. It handles prefix auto-detection by trying both the exact tag name and with the configured prefix. Returns TagInfo with all fields populated, or an error if the tag doesn't exist.

func (*Tagger) GetVersionWithDirtyCheck

func (t *Tagger) GetVersionWithDirtyCheck(ctx context.Context) (string, error)

GetVersionWithDirtyCheck returns the version string, appending "-dirty-<short-commit>" if there are uncommitted changes or if the latest tag is not on the current commit. If no tags exist, it returns "0.0.0-dev".

func (*Tagger) HasUncommittedChanges

func (t *Tagger) HasUncommittedChanges(ctx context.Context) (bool, error)

HasUncommittedChanges checks if there are uncommitted changes in the repository.

func (*Tagger) IsTagOnCurrentCommit

func (t *Tagger) IsTagOnCurrentCommit(ctx context.Context, tag string) (bool, error)

IsTagOnCurrentCommit checks if the given tag points to the current commit.

func (*Tagger) LatestStableTag added in v1.3.0

func (t *Tagger) LatestStableTag(ctx context.Context) (string, error)

LatestStableTag returns the most recent tag that is a stable (non-prerelease) SemVer version. It iterates over all matching tags (git-sorted, newest first) and returns the first one whose parsed version has no prerelease identifier. Returns an empty string if no stable tags are found.

func (*Tagger) LatestTag

func (t *Tagger) LatestTag(ctx context.Context) (string, error)

LatestTag returns the latest tag with the configured prefix, or empty string if none exists.

func (*Tagger) ListAllTags

func (t *Tagger) ListAllTags(ctx context.Context) ([]TagInfo, error)

ListAllTags returns all tags with the configured prefix, sorted by version (newest first). For each tag, it includes the commit hash, date, and message.

func (*Tagger) MoveTag added in v1.3.0

func (t *Tagger) MoveTag(ctx context.Context, tag, target, message string) error

MoveTag force-moves an existing tag to the target commit-ish. Uses git tag -f -a to preserve the annotated tag format. Respects the dry-run flag.

func (*Tagger) ParseLatestStableVersion added in v1.3.0

func (t *Tagger) ParseLatestStableVersion(ctx context.Context) (*version.Version, error)

ParseLatestStableVersion returns the parsed stable version from the latest stable tag. Returns nil if no stable tags exist.

func (*Tagger) ParseLatestVersion

func (t *Tagger) ParseLatestVersion(ctx context.Context, scheme version.Scheme) (*version.Version, error)

ParseLatestVersion returns the parsed version of the latest tag, or nil if no tag exists.

func (*Tagger) PushTag

func (t *Tagger) PushTag(ctx context.Context, tag string) error

PushTag pushes the tag to the remote repository. If dryRun is true, only logs the operation without pushing.

func (*Tagger) PushTagForce added in v1.3.0

func (t *Tagger) PushTagForce(ctx context.Context, tag string) error

PushTagForce force-pushes the tag to the remote repository. Use this after MoveTag to update the remote ref. Respects the dry-run flag.

func (*Tagger) ResolveCommit added in v1.3.0

func (t *Tagger) ResolveCommit(ctx context.Context, ref string) (string, error)

ResolveCommit resolves any ref (commit hash, branch name, HEAD, etc.) to a full commit hash.

func (*Tagger) ShortCommit

func (t *Tagger) ShortCommit(ctx context.Context) (string, error)

ShortCommit returns the short commit hash (first 7 characters).

func (*Tagger) TagExists

func (t *Tagger) TagExists(ctx context.Context, tag string) (bool, error)

TagExists checks if a tag already exists.

Jump to

Keyboard shortcuts

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