git

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package git provides functions for interacting with git repositories by shelling out to the git CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checkout added in v0.3.0

func Checkout(repoPath, branch string) error

Checkout switches to the given branch.

func CommitAuthors added in v0.3.0

func CommitAuthors(repoPath, branch, base string) ([]string, error)

CommitAuthors returns the set of unique author emails for all commits on branch that are not reachable from base. This identifies who contributed to the branch since it diverged.

func CommitDate

func CommitDate(repoPath, branch string) (time.Time, error)

CommitDate returns the author date of the latest commit on the given branch.

func CommitSubject added in v0.2.2

func CommitSubject(repoPath, ref string) (string, error)

CommitSubject returns the subject line of the latest commit on the given ref.

func CommitsAheadBehind added in v0.2.2

func CommitsAheadBehind(repoPath, branch, base string) (ahead int, behind int, err error)

CommitsAheadBehind returns the number of commits that branch is ahead of and behind base. This uses rev-list to count commits reachable from one ref but not the other.

func ConfigValue added in v0.3.0

func ConfigValue(repoPath, key string) (string, error)

ConfigValue returns the value of a git config key in the given repo.

func CreateTag added in v0.2.2

func CreateTag(repoPath, tagName, ref string) error

CreateTag creates a lightweight tag at the given ref.

func CurrentBranch

func CurrentBranch(repoPath string) (string, error)

CurrentBranch returns the name of the currently checked-out branch.

func DefaultBranch

func DefaultBranch(repoPath string) (string, error)

DefaultBranch returns the default branch name (main or master) by checking what the origin HEAD points to, falling back to a local heuristic.

func DeleteLocalBranch

func DeleteLocalBranch(repoPath, branch string, force bool) error

DeleteLocalBranch deletes a local branch. If force is true, uses -D instead of -d.

func DeleteRemoteBranch

func DeleteRemoteBranch(repoPath, remote, branch string) error

DeleteRemoteBranch deletes a branch on the given remote.

func Fetch

func Fetch(repoPath, remote string) error

Fetch fetches from the given remote.

func HasRemote

func HasRemote(repoPath, remote string) bool

HasRemote returns true if the given remote exists.

func HasRemoteBranch added in v0.2.2

func HasRemoteBranch(repoPath, remote, branch string) (bool, error)

HasRemoteBranch returns true if the given branch exists on the specified remote.

func HasUpstream added in v0.3.0

func HasUpstream(repoPath, branch string) bool

HasUpstream returns true if the given branch has a remote tracking branch configured.

func IsClean

func IsClean(repoPath string) (bool, error)

IsClean returns true if the working tree has no uncommitted changes.

func IsMerged

func IsMerged(repoPath, branch, base string) (bool, error)

IsMerged returns true if the given branch has been merged into base.

func IsRepo

func IsRepo(path string) bool

IsRepo returns true if the given path is inside a git repository.

func ListBranches

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

ListBranches returns all local branch names.

func MergeAbort added in v0.2.0

func MergeAbort(repoPath string) error

MergeAbort aborts an in-progress merge, restoring the branch to its pre-merge state.

func MergeBase added in v0.2.0

func MergeBase(repoPath string, ref1, ref2 string) (string, error)

MergeBase returns the best common ancestor commit between two refs.

func MergeTree added in v0.2.0

func MergeTree(repoPath string, base, local, remote string) (string, bool, error)

MergeTree performs a three-way merge-tree between base, local, and remote tree-ish references. It returns the merge output, whether conflicts were detected, and any error. This is a read-only operation that does not modify the working tree.

func MergedBranches

func MergedBranches(repoPath, base string) ([]string, error)

MergedBranches returns local branches that have been merged into the given base branch.

func Pull added in v0.2.0

func Pull(repoPath string, strategy string) error

Pull pulls from the default remote using the given strategy. Valid strategies: "rebase", "merge", "ff-only".

func RebaseAbort added in v0.2.0

func RebaseAbort(repoPath string) error

RebaseAbort aborts an in-progress rebase, restoring the branch to its pre-rebase state.

func RemoteURL

func RemoteURL(repoPath, remote string) (string, error)

RemoteURL returns the fetch URL of the given remote (usually "origin").

func RevListCount added in v0.7.0

func RevListCount(repoPath, spec string) (int, error)

RevListCount runs git rev-list --count with the given spec and returns the count. This is useful for checking how many commits one ref is ahead/behind another, e.g. RevListCount(repo, "HEAD..origin/main") returns how many commits HEAD is behind.

func RevParse added in v0.6.0

func RevParse(repoPath, ref string) (string, error)

RevParse returns the full SHA of the given ref.

func StashPop added in v0.2.0

func StashPop(repoPath string) error

StashPop applies and removes the most recent stash entry.

func StashPush added in v0.2.0

func StashPush(repoPath string, message string) (bool, error)

StashPush stashes the current working tree changes with the given message. It returns true if a stash entry was actually created, false if there was nothing to stash (git stash push exits 0 either way).

Types

This section is empty.

Jump to

Keyboard shortcuts

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