Documentation
¶
Index ¶
- Variables
- func Checkout(repoDir, branch string, force, create bool, startPoint string) error
- func Clone(ctx context.Context, path, remote, checkoutBranch string, ...) error
- func CommitAll(ctx context.Context, path, pathspec, message, authorName, authorEmail string) (string, error)
- func EnsureGitignoreHas(ctx context.Context, repo drivers.RepoStore, path string) (bool, error)
- func FetchBranches(ctx context.Context, path string, branches ...string) error
- func Hash(ctx context.Context, path, ref string) (string, error)
- func IsCommitHash(s string) bool
- func IsGitRepo(path string) bool
- func MergeWithBailOnConflict(path, branch string) (bool, error)
- func MergeWithStrategy(path, branch, strategy string) error
- func Run(ctx context.Context, path string, args ...string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyCommit = errors.New("nothing to commit")
ErrEmptyCommit is returned by CommitAll when there are no changes to commit.
var ErrRefNotFound = errors.New("git reference not found")
Functions ¶
func Checkout ¶ added in v0.87.0
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 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
EnsureGitignoreHas ensures the given path is listed in .gitignore. Returns true if .gitignore was modified.
func FetchBranches ¶ added in v0.87.0
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
Hash returns the commit hash for the given ref. Returns ErrRefNotFound if the ref does not resolve.
func IsCommitHash ¶ added in v0.87.0
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
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 ¶
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
MergeWithStrategy merge a branch into the current branch using the specified strategy.
func Run ¶ added in v0.87.0
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.