git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package git provides VCS utility functions to interact with Git repositories. See https://git-scm.com for more details about Git.

It makes use of the "github.com/go-git/go-git/v5" module, a highly extensible Git implementation in pure Go, instead of just trying to use the Git binary executable that may have been installed on the current system.

The "github.com/Masterminds/semver/v3" module is used to provide a stable and flexible way to work with "Semantic Versions". See https://semver.org for more details about "SemVer".

Index

Constants

View Source
const (
	// MaxSuitableTagCandidates is the maximum search amount of suitable tag candidates in all commits of the current
	// branch.
	// The value is the same like the default value of Git.
	MaxSuitableTagCandidates = 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	// Version is the semantic version.
	// See https://semver.org for more details.
	*semver.Version

	// CommitsAhead is the amount of commits ahead to the latest Git version tag in the current branch.
	CommitsAhead int

	// CommitHash is the hash of the latest commit in the current branch.
	CommitHash plumbing.Hash

	// LatestVersionTag is the latest Git version tag in the current branch.
	LatestVersionTag *plumbing.Reference
}

Version stores version information and metadata derived from a Git repository.

func DeriveVersion

func DeriveVersion(defaultVersion, repositoryPath string) (*Version, error)

DeriveVersion derives version information and metadata from a Git repository. It searches for the latest SemVer (https://semver.org) compatible version tag in the current branch and falls back to the given default version if no tag is found. If at least one tag is found, but it is not the latest commit of the current branch, the build metadata is appended, consisting of the amount of commits ahead and the shortened reference hash (8 digits) of the latest commit from the current branch.

This function is an early implementation of the Git "describe" command because support in the "github.com/go-git/go-git/v5" module has not been implemented yet. See the full compatibility comparison documentation with Git at https://github.com/go-git/go-git/blob/master/COMPATIBILITY.md as well as the proposed Git "describe" command implementation at https://github.com/src-d/go-git/pull/816 for more details.

Jump to

Keyboard shortcuts

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