Documentation
¶
Index ¶
- Constants
- func CheckoutBranch(repoPath, branch string) error
- func CreateCommit(repoPath, message string) (string, error)
- func EnsureAbsoluteHooksPath(repoPath string) error
- func FormatExcludeArgs(patterns []string) []string
- 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, extraExcludes ...string) (string, error)
- func GetDiffLimited(repoPath, sha string, maxBytes int, extraExcludes ...string) (string, bool, error)
- func GetDirtyDiff(repoPath string, extraExcludes ...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 GetPatchID(repoPath, sha string) string
- func GetRangeCommits(repoPath, rangeRef string) ([]string, error)
- func GetRangeDiff(repoPath, rangeRef string, extraExcludes ...string) (string, error)
- func GetRangeDiffLimited(repoPath, rangeRef string, maxBytes int, extraExcludes ...string) (string, bool, 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 LooksLikeSHA(s string) bool
- func ParseRange(ref string) (start, end string, ok bool)
- func ReadFile(repoPath, sha, filePath string) ([]byte, error)
- func ResetWorkingTree(repoPath string) error
- func ResolveGitDir(repoPath string) (string, error)
- func ResolveSHA(repoPath, ref string) (string, error)
- func ReviewPathspecArgs(extraExcludes ...string) []string
- func ShortRef(ref string) string
- func ShortSHA(sha string) string
- func ValidateWorktreeForRepo(worktreePath, repoRoot string) bool
- func WorktreePathForBranch(repoPath, branch string) (string, bool, 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 EnsureAbsoluteHooksPath ¶ added in v0.46.1
EnsureAbsoluteHooksPath checks whether core.hooksPath is set to a relative value and, if so, resolves it to an absolute path and updates the git config. Relative hooks paths break linked worktrees because git resolves them from the worktree root, not the main repo root.
func FormatExcludeArgs ¶ added in v0.49.0
FormatExcludeArgs converts user-provided exclude patterns (filenames or globs) into git pathspec arguments. Plain names without path separators get both **/name (file match) and **/name/** (directory subtree) so they work whether the name is a file or directory. Leading-slash patterns (/vendor) are root-anchored — no **/ prefix. Patterns containing "/" are passed through as-is. FormatExcludeArgs converts user-provided exclude patterns into git pathspec arguments suitable for appending after "--".
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. Uses symbolic-ref (without --short) and strips refs/heads/ directly, because both rev-parse --abbrev-ref and symbolic-ref --short can return "heads/branch" when the name is ambiguous with another ref (remote tracking branch, tag, etc.).
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. Extra exclude patterns (filenames or globs) are appended to the built-in exclusion list.
func GetDiffLimited ¶ added in v0.49.0
func GetDiffLimited( repoPath, sha string, maxBytes int, extraExcludes ...string, ) (string, bool, error)
GetDiffLimited returns up to maxBytes of a commit diff and reports whether the output was truncated before the full diff was read.
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. Extra exclude patterns (filenames or globs) are appended to the built-in list.
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. Relative paths are resolved against the main repository root (not the worktree root) so that linked worktrees share the same hooks directory.
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 GetPatchID ¶ added in v0.33.0
GetPatchID returns the stable patch-id for a commit. Patch-ids are content-based hashes of the diff, so two commits with the same code change (e.g. before and after a rebase) share the same patch-id. Returns "" for merge commits, empty commits, or on any error.
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. Extra exclude patterns (filenames or globs) are appended to the built-in exclusion list.
func GetRangeDiffLimited ¶ added in v0.49.0
func GetRangeDiffLimited( repoPath, rangeRef string, maxBytes int, extraExcludes ...string, ) (string, bool, error)
GetRangeDiffLimited returns up to maxBytes of a range diff and reports whether the output was truncated before the full diff was read.
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 LooksLikeSHA ¶ added in v0.51.0
LooksLikeSHA returns true if s looks like a git commit SHA (7-40 hex chars, case-insensitive). The 7-char minimum matches git's default abbreviation length and safely excludes short hex task labels like "dead" or "cafe".
func ParseRange ¶
ParseRange splits a range ref into start and end
func ResetWorkingTree ¶
ResetWorkingTree discards all uncommitted changes (staged and unstaged)
func ResolveGitDir ¶ added in v0.51.0
ResolveGitDir returns the absolute path to the .git directory for a repository, correctly handling worktrees and MSYS-style paths on Windows.
func ResolveSHA ¶
ResolveSHA resolves a ref (like HEAD) to a full SHA
func ReviewPathspecArgs ¶ added in v0.49.0
ReviewPathspecArgs returns the git pathspec arguments roborev uses for review diffs: the repo root plus built-in and configured exclusions.
func ShortRef ¶ added in v0.34.0
ShortRef abbreviates a git ref for display. SHA-like tokens (hex strings longer than 7 chars) are truncated to 7 chars. Range refs like "abc123def..xyz789abc" become "abc123d..xyz789a". Non-hex refs (branch names, task labels) pass through unchanged.
func ShortSHA ¶ added in v0.34.0
ShortSHA returns the first 7 characters of a SHA hash, or the full string if shorter. Matches git's default abbreviation.
func ValidateWorktreeForRepo ¶ added in v0.49.0
ValidateWorktreeForRepo checks that worktreePath is a git checkout whose main repository root matches repoRoot. Returns true if the worktree is valid for the given repo. Returns false (without error) if the path doesn't exist, isn't a git repo, or belongs to a different repository.
func WorktreePathForBranch ¶ added in v0.36.0
WorktreePathForBranch returns the worktree directory where branch is checked out. If the branch is checked out in any worktree (including the main repo), returns that path and true. If the branch is not checked out anywhere, returns repoPath and false. Returns a non-nil error if the git command fails. An empty branch always returns repoPath, true, nil.
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