git

package module
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 12 Imported by: 0

README

Git

Build Status

Helper functions for Git in use across Commitsar and Release Notary

Documentation

Overview

Package git is a wrapper for Git actions. The main purpose is the unify some functionality in this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCommitNotOnTag is returned by CurrentTag if the commit is not on a tag
	ErrCommitNotOnTag = errors.New("current commit is not on a tag")
)
View Source
var (
	// ErrPrevTagNotAvailable is returned when no previous tag is found.
	ErrPrevTagNotAvailable = errors.New("previous tag is not available")
)

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Hash      Hash
	Message   string
	Author    Signature
	Committer Signature
}

Commit represents a git commit - compatible with object.Commit

type Git

type Git struct {
	Path string
}

Git is the struct used to house all methods in use in Commitsar.

func OpenGit

func OpenGit(path string) (*Git, error)

OpenGit loads Repo on path and returns a new Git struct to work with.

func (*Git) BranchDiffCommits

func (g *Git) BranchDiffCommits(branchA string, branchB string) ([]Hash, error)

BranchDiffCommits compares commits from 2 branches and returns of a diff of them. Uses git log with exclusion syntax for efficient comparison - finds commits in branchA that are not in branchB. This is more efficient than fetching all commits from both branches and comparing them.

func (*Git) Commit

func (g *Git) Commit(hash Hash) (*Commit, error)

Commit finds a commit based on commit hash and returns the Commit object

func (*Git) CommitsBetween

func (g *Git) CommitsBetween(from Hash, to Hash) ([]Hash, error)

CommitsBetween returns a slice of commit hashes between two commits

func (*Git) CommitsOnBranch

func (g *Git) CommitsOnBranch(
	branchCommit Hash,
) ([]Hash, error)

CommitsOnBranch iterates through all references and returns commit hashes on given branch. \n Important to note is that this will provide all commits from anything the branch is connected to.

func (*Git) CommitsOnBranchSimple

func (g *Git) CommitsOnBranchSimple(
	branchCommit Hash,
) ([]SimpleCommit, error)

CommitsOnBranchSimple iterates through all references and returns simpleCommits on given branch. \n Important to note is that this will provide all commits from anything the branch is connected to.

func (*Git) CurrentBranch

func (g *Git) CurrentBranch() (*Reference, error)

CurrentBranch returns the reference HEAD is at right now. In detached HEAD state, it returns a reference with name "HEAD".

func (*Git) CurrentCommit

func (g *Git) CurrentCommit() (*Commit, error)

CurrentCommit returns the commit that HEAD is at

func (*Git) CurrentTag

func (g *Git) CurrentTag() (*Tag, error)

CurrentTag returns a Tag if the current HEAD is on a tag

func (*Git) LatestCommitOnBranch

func (g *Git) LatestCommitOnBranch(desiredBranch string) (*Commit, error)

LatestCommitOnBranch resolves a revision and then returns the latest commit on it.

func (*Git) PreviousTag

func (g *Git) PreviousTag(currentHash Hash) (*Tag, error)

PreviousTag sorts tags based on when their commit happened and returns the one previous to the current.

func (*Git) Tags

func (g *Git) Tags() ([]*Tag, error)

type Hash

type Hash [20]byte

Hash represents a git commit hash (20 bytes) - compatible with plumbing.Hash

func MustHash

func MustHash(s string) Hash

MustHash creates a Hash from a hex string, panicking on error

func NewHash

func NewHash(s string) (Hash, error)

NewHash creates a Hash from a hex string

func (Hash) String

func (h Hash) String() string

String returns the hex string representation of the hash

type Reference

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

Reference represents a git reference - compatible with plumbing.Reference

func NewReference

func NewReference(name string, hash Hash) *Reference

NewReference creates a new Reference

func (*Reference) Hash

func (r *Reference) Hash() Hash

Hash returns the reference hash

func (*Reference) Name

func (r *Reference) Name() string

Name returns the reference name

type Signature

type Signature struct {
	Name  string
	Email string
	When  time.Time
}

Signature represents a git signature

type SimpleCommit

type SimpleCommit struct {
	Hash    Hash
	Message string
}

SimpleCommit is a slimed down commit object of just Hash and Message

type Tag

type Tag struct {
	Name string
	Hash Hash
	Date time.Time
}

Tag houses some common info about tags.

Jump to

Keyboard shortcuts

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