gitutil

package
v0.87.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCommit = errors.New("nothing to commit")

ErrEmptyCommit is returned by CommitAll when there are no changes to commit.

View Source
var ErrRefNotFound = errors.New("git reference not found")

Functions

func Checkout added in v0.87.0

func Checkout(repoDir, branch string, force, create bool, startPoint string) error

Checkout checks out a branch using the git command. If create is true, it creates the branch (using -B) at the given startPoint. go-git wipes out git-ignored changes during checkout so must use the git command.

func Clone added in v0.87.0

func Clone(ctx context.Context, path, remote, checkoutBranch string, singleBranch, shallow bool) error

func CommitAll added in v0.87.0

func CommitAll(ctx context.Context, path, pathspec, message, authorName, authorEmail string) (string, error)

CommitAll stages all changes in the working tree and creates a commit with the given message. If pathspec is non-empty, staging and the empty-commit check are scoped to that pathspec. The commit's author and committer are set to the provided name and email. Returns the new commit hash, or ErrEmptyCommit if there are no changes to commit.

func EnsureGitignoreHas added in v0.87.0

func EnsureGitignoreHas(ctx context.Context, repo drivers.RepoStore, path string) (bool, error)

EnsureGitignoreHas ensures the given path is listed in .gitignore. Returns true if .gitignore was modified.

func FetchBranches added in v0.87.0

func FetchBranches(ctx context.Context, path string, branches ...string) error

FetchBranches fetches the specified branches from the remote repository. If a branch doesn't exist on the remote, it will be skipped without returning an error.

func Hash added in v0.87.0

func Hash(ctx context.Context, path, ref string) (string, error)

Hash returns the commit hash for the given ref. Returns ErrRefNotFound if the ref does not resolve.

func IsCommitHash added in v0.87.0

func IsCommitHash(s string) bool

IsCommitHash reports whether s is a full hex commit hash (SHA-1 or SHA-256). Use it to validate untrusted hashes before passing them as git CLI arguments: it rules out strings that git would interpret as flags or other revision syntax.

func IsGitRepo added in v0.87.0

func IsGitRepo(path string) bool

IsGitRepo reports whether path is inside a git working tree. Returns true for the repo root as well as any subdirectory of it.

func MergeWithBailOnConflict

func MergeWithBailOnConflict(path, branch string) (bool, error)

MergeWithBailOnConflict attempts to merge a branch into the current branch and aborts if there are conflicts. Returns true if merge was successful, false if there were conflicts (but abort succeeded). Returns an error if the merge failed for a reason other than conflicts, or if both merge and abort fail.

func MergeWithStrategy added in v0.87.0

func MergeWithStrategy(path, branch, strategy string) error

MergeWithStrategy merge a branch into the current branch using the specified strategy.

func Run added in v0.87.0

func Run(ctx context.Context, path string, args ...string) (string, error)

Run executes a git command with the specified arguments in the given path and returns its output or an error. If path is empty, the command runs without -C (use for commands like `clone` that take an explicit destination). Use it to run one-off git commands that don't fit into the other helper functions in this package.

Types

This section is empty.

Jump to

Keyboard shortcuts

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