Help us shape the future of Go! Take the 2026 Go Developer Survey

gitutil

package
v0.8.19 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gitutil offers utilities for parsing and extracting Git repository metadata, branch names, tags, and clone URLs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoGitBinary is an error returned when no git binary is found.
	ErrNoGitBinary = errors.New("no git binary found")
	// ErrNotAGitDir is an error returned when a given directory is not a git dir.
	ErrNotAGitDir = errors.New("not a git directory")
	// ErrCouldNotDetectRemote is an error returned when git remote could not be detected or parsed.
	ErrCouldNotDetectRemote = errors.New("could not auto-detect or parse Git remote URL")
	// ErrCouldNotDetectGitHash is an error returned when git hash could not be detected.
	ErrCouldNotDetectGitHash = errors.New("could not auto-detect or parse Git hash")
	// ErrCouldNotDetectGitShortHash is an error returned when git short hash could not be detected.
	ErrCouldNotDetectGitShortHash = errors.New("could not auto-detect or parse Git short hash")
	// ErrCouldNotDetectGitContentHash is an error returned when git tree hash could not be detected.
	ErrCouldNotDetectGitContentHash = errors.New("could not auto-detect or parse Git content hash")
	// ErrCouldNotDetectGitBranch is an error returned when git branch could not be detected.
	ErrCouldNotDetectGitBranch = errors.New("could not auto-detect or parse Git branch")
	// ErrCouldNotDetectGitTags is an error returned when git tags could not be detected.
	ErrCouldNotDetectGitTags = errors.New("could not auto-detect or parse Git tags")
	// ErrCouldNotDetectGitRefs is an error returned when git refs could not be detected.
	ErrCouldNotDetectGitRefs = errors.New("could not auto-detect or parse Git refs")
)

Functions

func ParseCoAuthorsFromBody

func ParseCoAuthorsFromBody(body string) []string

ParseCoAuthorsFromBody returns a list of coauthor emails from a git body.

func ParseGitRemoteURL

func ParseGitRemoteURL(gitURL string) (string, error)

ParseGitRemoteURL converts a gitURL like user@host.com:path/to.git or https://host.com/path/to.git to host.com/path/to.

func ReferenceWithGitMeta

func ReferenceWithGitMeta(ref domain.Reference, gitMeta *GitMetadata) domain.Reference

ReferenceWithGitMeta applies git metadata to the target naming.

Types

type GitMetadata

type GitMetadata struct {
	CommitterTimestamp   string
	AuthorTimestamp      string
	RemoteURL            string
	GitURL               string
	Hash                 string
	ShortHash            string
	ContentHash          string
	RelDir               string
	AuthorName           string
	AuthorEmail          string
	BaseDir              string
	Branch               []string
	Tags                 []string
	CoAuthors            []string
	Refs                 []string
	BranchOverrideTagArg bool
}

GitMetadata is a collection of git information about a certain directory.

func Metadata

func Metadata(ctx context.Context, dir, gitBranchOverride string) (*GitMetadata, error)

Metadata performs git metadata detection on the provided directory.

func (*GitMetadata) Clone

func (gm *GitMetadata) Clone() *GitMetadata

Clone returns a copy of the GitMetadata object.

Jump to

Keyboard shortcuts

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