git

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInRepository = errors.New("path is not inside a git repository")

ErrNotInRepository indicates that a file path does not reside inside a (discoverable) git repository.

View Source
var ErrUntracked = errors.New("file has no commit history in repository")

ErrUntracked indicates that a file exists on disk and inside a git repository, but has no commit history for that path.

Functions

This section is empty.

Types

type Client

type Client struct{}

Client represents a Git client using go-git

func New

func New() *Client

New creates a new Git client

func (*Client) CloneAtTag added in v0.3.0

func (c *Client) CloneAtTag(ctx context.Context, repoURL, tag, destDir string) error

CloneAtTag clones the repository at the given tag into destDir. It first attempts a shallow single-branch clone (cheap); some servers reject shallow tag fetches, in which case it falls back to a full clone of the tag ref.

func (*Client) CloneRepository

func (c *Client) CloneRepository(ctx context.Context, repoURL string) (*git.Repository, error)

CloneRepository clones a repository to memory for more advanced operations

func (*Client) FilterTags

func (c *Client) FilterTags(tags []string, pattern string) []string

FilterTags filters tags based on a pattern

func (*Client) FilterTagsWithPrefix

func (c *Client) FilterTagsWithPrefix(tags []string, prefix string) []string

FilterTagsWithPrefix filters tags that start with a specific prefix

func (*Client) GetCommitFromClone

func (c *Client) GetCommitFromClone(ctx context.Context, repoURL, commitSHA string) (*object.Commit, error)

GetCommitFromClone gets detailed commit information by cloning the repository

func (*Client) GetCommitInfo

func (c *Client) GetCommitInfo(ctx context.Context, repoURL, commitSHA string) (*CommitInfo, error)

GetCommitInfo gets information about a commit

func (*Client) GetCommitSHAForTag

func (c *Client) GetCommitSHAForTag(ctx context.Context, repoURL, tag string) (string, error)

GetCommitSHAForTag gets the commit SHA for a specific tag

func (*Client) GetDefaultBranch

func (c *Client) GetDefaultBranch(ctx context.Context, repoURL string) (string, error)

GetDefaultBranch gets the default branch of the repository

func (*Client) GetFirstValidTag

func (c *Client) GetFirstValidTag(ctx context.Context, repoURL string, filter types.VersionFilterFunc) (string, error)

GetFirstValidTag finds the first tag that passes all filtering criteria

func (*Client) GetLatestTag

func (c *Client) GetLatestTag(ctx context.Context, repoURL string) (string, error)

GetLatestTag returns the latest tag from a Git repository

func (*Client) GetLatestTagWithFilter

func (c *Client) GetLatestTagWithFilter(ctx context.Context, repoURL, filter string) (string, error)

GetLatestTagWithFilter returns the latest tag that matches the filter

func (*Client) GetTagInfo

func (c *Client) GetTagInfo(ctx context.Context, repoURL, tagName string) (*TagInfo, error)

GetTagInfo gets detailed information about a tag

func (*Client) GetTags

func (c *Client) GetTags(ctx context.Context, repoURL string) ([]string, error)

GetTags returns all tags from a Git repository

func (*Client) GetTagsWithFilter

func (c *Client) GetTagsWithFilter(ctx context.Context, repoURL, filterPrefix, filterContains string) ([]string, error)

GetTagsWithFilter returns filtered tags from a Git repository with early termination

func (*Client) HeadCommit added in v0.3.0

func (c *Client) HeadCommit(_ context.Context, dir string) (string, error)

HeadCommit returns the commit SHA the checkout at dir points to. ctx is accepted for interface consistency with the client's other methods; the underlying go-git read is local-disk-only and doesn't support cancellation.

func (*Client) ListBranches

func (c *Client) ListBranches(ctx context.Context, repoURL string) ([]string, error)

ListBranches lists all branches in the repository

func (*Client) VerifyCommitExists

func (c *Client) VerifyCommitExists(ctx context.Context, repoURL, commitSHA string) (bool, error)

VerifyCommitExists verifies that a commit SHA exists in the repository

type CommitInfo

type CommitInfo struct {
	SHA        string
	Repository string
	Message    string
	Author     string
	Date       string
}

CommitInfo represents information about a Git commit

type FileCommitInfo added in v0.3.0

type FileCommitInfo struct {
	// Time is the committer time of the last commit that touched the file.
	Time time.Time
	// Hash is the last commit's SHA (hex).
	Hash string
	// Shallow reports whether the containing repository has truncated
	// (shallow) history.
	Shallow bool
	// Dirty reports whether the on-disk content differs from the file's
	// blob at HEAD.
	Dirty bool
}

FileCommitInfo describes the last commit that touched a file, plus working-tree state relevant to a "how stale is this checkout" heuristic.

func LastCommitInfo added in v0.3.0

func LastCommitInfo(ctx context.Context, filePath string) (*FileCommitInfo, error)

LastCommitInfo locates the git repository containing filePath and returns information about the last commit that touched it, along with whether the on-disk content is dirty relative to HEAD and whether the repository has shallow history.

It returns ErrNotInRepository if filePath is not inside a discoverable git repository, and ErrUntracked if the file has no commit history.

type Repository

type Repository struct {
	URL    string
	Branch string
}

Repository represents a Git repository

type TagInfo

type TagInfo struct {
	Name       string
	SHA        string
	Message    string
	Tagger     string
	TaggerDate string
}

TagInfo represents information about a Git tag

Jump to

Keyboard shortcuts

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