Documentation
¶
Index ¶
- Constants
- func CheckoutBranch(repoPath, branch string) error
- func CreateCommit(repoPath, message string) (string, error)
- func GetBranchName(repoPath, sha string) string
- func GetCommitsSince(repoPath, mergeBase string) ([]string, error)
- func GetCurrentBranch(repoPath string) string
- func GetDefaultBranch(repoPath string) (string, error)
- func GetDiff(repoPath, sha string) (string, error)
- func GetDirtyDiff(repoPath string) (string, error)
- func GetFilesChanged(repoPath, sha string) ([]string, error)
- func GetHooksPath(repoPath string) (string, error)
- func GetMainRepoRoot(path string) (string, error)
- func GetMergeBase(repoPath, ref1, ref2 string) (string, error)
- func GetParentCommits(repoPath, sha string, count int) ([]string, error)
- func GetRangeCommits(repoPath, rangeRef string) ([]string, error)
- func GetRangeDiff(repoPath, rangeRef string) (string, error)
- func GetRangeFilesChanged(repoPath, rangeRef string) ([]string, error)
- func GetRangeStart(repoPath, rangeRef string) (string, error)
- func GetRemoteURL(repoPath, remoteName string) string
- func GetRepoRoot(path string) (string, error)
- func GetStat(repoPath, sha string) (string, error)
- func HasUncommittedChanges(repoPath string) (bool, error)
- func IsAncestor(repoPath, ancestor, descendant string) (bool, error)
- func IsRange(ref string) bool
- func IsRebaseInProgress(repoPath string) bool
- func IsUnbornHead(repoPath string) bool
- func IsWorkingTreeClean(repoPath string) bool
- func LocalBranchName(branch string) string
- func ParseRange(ref string) (start, end string, ok bool)
- func ReadFile(repoPath, sha, filePath string) ([]byte, error)
- func ResetWorkingTree(repoPath string) error
- func ResolveSHA(repoPath, ref string) (string, error)
- type CommitError
- type CommitInfo
Constants ¶
const EmptyTreeSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
EmptyTreeSHA is the SHA of an empty tree in git, used for diffing against the root commit or repos with no commits.
Variables ¶
This section is empty.
Functions ¶
func CheckoutBranch ¶ added in v0.32.0
CheckoutBranch switches to the given branch in the repository.
func CreateCommit ¶
CreateCommit stages all changes and creates a commit with the given message Returns the SHA of the new commit
func GetBranchName ¶
GetBranchName returns a human-readable branch reference for a commit. Returns something like "main", "feature/foo", or "main~3" depending on where the commit is relative to branch heads. Returns empty string on error or timeout (2 second limit to avoid blocking UI).
func GetCommitsSince ¶
GetCommitsSince returns all commits from mergeBase to HEAD (exclusive of mergeBase) Returns commits in chronological order (oldest first)
func GetCurrentBranch ¶
GetCurrentBranch returns the current branch name, or empty string if detached HEAD
func GetDefaultBranch ¶
GetDefaultBranch detects the default branch (from origin/HEAD, or main/master locally)
func GetDiff ¶
GetDiff returns the full diff for a commit, excluding generated files like lock files
func GetDirtyDiff ¶
GetDirtyDiff returns a diff of all uncommitted changes including untracked files. The diff includes both tracked file changes (via git diff HEAD) and untracked files formatted as new-file diff entries. Excludes generated files like lock files.
func GetFilesChanged ¶
GetFilesChanged returns the list of files changed in a commit
func GetHooksPath ¶
GetHooksPath returns the path to the hooks directory, respecting core.hooksPath
func GetMainRepoRoot ¶
GetMainRepoRoot returns the main repository root, resolving through worktrees. For a regular repository or submodule, this returns the same as GetRepoRoot. For a worktree, this returns the main repository's root path.
func GetMergeBase ¶
GetMergeBase returns the merge-base (common ancestor) between two refs
func GetParentCommits ¶
GetParentCommits returns the N commits before the given commit (not including it) Returns commits in reverse chronological order (most recent parent first)
func GetRangeCommits ¶
GetRangeCommits returns all commits in a range (oldest first)
func GetRangeDiff ¶
GetRangeDiff returns the combined diff for a range, excluding generated files like lock files
func GetRangeFilesChanged ¶ added in v0.31.0
GetRangeFilesChanged returns the list of files changed in a range (e.g. "mergeBase..HEAD")
func GetRangeStart ¶
GetRangeStart returns the start commit (first parent before range) for context lookup
func GetRemoteURL ¶
GetRemoteURL returns the URL for a git remote. If remoteName is empty, tries "origin" first, then any other remote. Returns empty string if no remotes exist.
func GetRepoRoot ¶
GetRepoRoot returns the root directory of the git repository
func HasUncommittedChanges ¶
HasUncommittedChanges returns true if there are uncommitted changes (staged, unstaged, or untracked files)
func IsAncestor ¶
IsAncestor checks if ancestor is an ancestor of descendant. Returns (true, nil) if ancestor is reachable from descendant via the commit graph. Returns (false, nil) if ancestor is not an ancestor (git exits with status 1). Returns (false, error) for git errors (e.g., bad object, repo issues).
func IsRebaseInProgress ¶
IsRebaseInProgress returns true if a rebase operation is in progress
func IsUnbornHead ¶ added in v0.21.0
IsUnbornHead returns true if the repository has an unborn HEAD (no commits yet). Returns false if HEAD points to a valid commit, if the path is not a git repo, or if HEAD is corrupt (e.g., ref pointing to a missing object).
func IsWorkingTreeClean ¶
IsWorkingTreeClean returns true if the working tree has no uncommitted or untracked changes
func LocalBranchName ¶
LocalBranchName strips the "origin/" prefix from a branch name if present. This normalizes branch names for comparison since GetDefaultBranch may return "origin/main" while GetCurrentBranch returns "main".
func ParseRange ¶
ParseRange splits a range ref into start and end
func ResetWorkingTree ¶
ResetWorkingTree discards all uncommitted changes (staged and unstaged)
func ResolveSHA ¶
ResolveSHA resolves a ref (like HEAD) to a full SHA
Types ¶
type CommitError ¶ added in v0.32.0
type CommitError struct {
Phase string // "add" or "commit"
HookFailed bool // true when a hook caused the failure
Stderr string
Err error
}
CommitError represents a failure during CreateCommit. Phase distinguishes "add" failures (lockfile, permissions) from "commit" failures (hooks, empty commit, identity issues). HookFailed is set by probing whether a hookless commit would succeed — true means a hook (pre-commit, commit-msg, etc.) caused the failure.
func (*CommitError) Error ¶ added in v0.32.0
func (e *CommitError) Error() string
func (*CommitError) Unwrap ¶ added in v0.32.0
func (e *CommitError) Unwrap() error
type CommitInfo ¶
type CommitInfo struct {
SHA string
Author string
Subject string
Body string // Full commit message body (excluding subject)
Timestamp time.Time
}
CommitInfo holds metadata about a commit
func GetCommitInfo ¶
func GetCommitInfo(repoPath, sha string) (*CommitInfo, error)
GetCommitInfo retrieves commit metadata