Documentation
¶
Index ¶
- func BranchExists(dir, branch string) bool
- func Checkout(dir, branch string) error
- func CommitExists(dir, rev string) bool
- func CommitsBehind(dir, baseCommit, targetRef string) (int, error)
- func CreateWorktree(repoDir, worktreePath, branch string) error
- func CurrentBranch(dir string) (string, error)
- func DiffFile(dir, baseRef, path string) (string, error)
- func DiffFileRange(dir, baseRef, branchRef, path string) (string, error)
- func DiffNameStatus(dir, baseRef string) (map[string]string, error)
- func DiffNameStatusRange(dir, baseRef, branchRef string) (map[string]string, error)
- func DiffStat(dir, baseRef string) (added, removed int, err error)
- func DiffStatRange(dir, baseRef, branchRef string) (added, removed int, err error)
- func EffectiveTarget(dir, target string) string
- func Fetch(dir string) error
- func FilterLineEndingWarnings(stderr string) string
- func GetCommitSubjects(dir, base string) ([]string, error)
- func HasRemote(dir string) bool
- func IsAncestor(dir, ancestor, descendant string) (bool, error)
- func IsClean(dir string) (bool, error)
- func IsPushed(dir string) (bool, error)
- func ListRefs(dir string, patterns ...string) (map[string]string, error)
- func LocalPush(dir, targetBranch string) error
- func MergeBase(dir, ref1, ref2 string) (string, error)
- func MergeBaseForkPoint(dir, upstream, commit string) (string, error)
- func MergeConflictFiles(dir, targetRef, headRef string) ([]string, error)
- func Output(dir string, args ...string) (string, error)
- func OverlappingFiles(dir, baseCommit, workerHead, targetRef string) ([]string, error)
- func RebaseOnto(dir, target string) error
- func ResetHard(dir string) error
- func ResolveDiffBase(dir string, branchRef, baseBranch string) (string, error)
- func RevListCount(dir, baseCommit, headRef string) (int, error)
- func Run(dir string, args ...string) error
- func RunQuiet(dir string, args ...string) error
- func RunSilent(dir string, args ...string) error
- func RunWithStderrFilter(dir string, stderrFilter func(string) string, args ...string) error
- func SetupBranch(dir string, taskBranch string, baseBranch string, baseCommit string) error
- func ShowDiffStat(dir, commit string) (added, removed int, ok bool, err error)
- func SquashCommits(dir, mergeBase, message string) error
- func Switch(dir, branch, startPoint string) error
- type CommitMeta
- type DiffFileStat
- type Error
- type IntegrationReason
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists checks if a branch exists in the repository.
func CommitExists ¶
CommitExists returns whether rev resolves to a commit object.
func CommitsBehind ¶
CommitsBehind returns how many commits targetRef is ahead of baseCommit. Equivalent to: git rev-list --count <baseCommit>..<targetRef>
func CreateWorktree ¶
CreateWorktree creates a git worktree.
func CurrentBranch ¶
CurrentBranch returns the current branch name.
func DiffFileRange ¶
DiffFileRange returns the unified diff for a single file path for base..branch.
func DiffNameStatus ¶
DiffNameStatus returns per-file status codes compared to baseRef. Includes both committed changes on the current branch and uncommitted changes.
Output format: - <status>\t<path> - Renames/copies: R<score>\t<old>\t<new> (we return status "R" for <new>)
func DiffNameStatusRange ¶
DiffNameStatusRange returns per-file status codes for base..branch.
func DiffStat ¶
DiffStat returns lines added and removed compared to baseRef. Includes both committed changes on the current branch and uncommitted changes.
func DiffStatRange ¶ added in v0.2.0
DiffStatRange returns summed added/removed lines for base..branch.
This is committed-history only (does not include uncommitted workspace changes).
func EffectiveTarget ¶
EffectiveTarget returns target or origin/target if origin is ahead.
Note: This is used for *observation/detection* (e.g. noticing merges that happened upstream after a fetch), not for preferring remotes during user-facing operations.
func FilterLineEndingWarnings ¶
FilterLineEndingWarnings removes common git line-ending conversion warnings.
func GetCommitSubjects ¶
GetCommitSubjects returns commit subjects from base..HEAD.
func IsAncestor ¶ added in v0.2.0
IsAncestor reports whether ancestor is reachable from descendant.
This wraps `git merge-base --is-ancestor`: - returns (true, nil) if ancestor is an ancestor of descendant - returns (false, nil) if ancestor is NOT an ancestor of descendant - returns (false, err) for other git errors (missing commits, not a repo, etc.)
func ListRefs ¶
ListRefs returns a map of full refname -> object SHA for the given ref namespaces/patterns.
Example patterns: - "refs/heads" - "refs/remotes/origin"
It runs a single `git for-each-ref` command and is intended to be fast.
func LocalPush ¶
LocalPush fast-forwards targetBranch to current HEAD.
If targetBranch is checked out in another worktree (e.g. the user's main worktree), update it using a fast-forward merge so local uncommitted changes are preserved when they don't overlap (git-like behavior).
If targetBranch is not checked out anywhere, update only the ref.
func MergeBaseForkPoint ¶ added in v0.2.0
MergeBaseForkPoint returns the fork-point merge-base between upstream and commit.
This is useful for finding a stable "PR base" even if the branch tip is already reachable from upstream (e.g., fast-forward merged), as long as upstream's reflog still contains the previous base tip.
func MergeConflictFiles ¶
MergeConflictFiles returns the list of files that would conflict when merging headRef into targetRef.
This is a non-mutating check intended for preflight/status displays. It uses `git merge-tree` to simulate the merge and only reports files when git reports a conflict.
func OverlappingFiles ¶
OverlappingFiles returns files changed in both: - baseCommit..workerHead (worker changes) - baseCommit..targetRef (base branch changes)
This is a heuristic for potential merge conflicts.
func RebaseOnto ¶
RebaseOnto rebases current branch onto target. Aborts and returns error on conflict. On conflict, returns extracted CONFLICT lines (if any).
func ResolveDiffBase ¶
ResolveDiffBase returns the base commit to diff against.
Always compute merge-base between branchRef (e.g. "HEAD" or the task branch) and the local baseBranch.
func RevListCount ¶ added in v0.2.0
RevListCount returns how many commits are reachable from headRef but not baseCommit. Equivalent to: git rev-list --count <baseCommit>..<headRef>
func RunWithStderrFilter ¶
RunWithStderrFilter runs a git command, streaming stdout and filtering stderr (on success only). This is useful for removing known-benign warnings that would otherwise pollute CLI output.
If the command fails, stderr is not filtered.
func SetupBranch ¶
SetupBranch sets up the git branch for a task (local-first).
func ShowDiffStat ¶
ShowDiffStat returns lines added/removed for a single commit (like `git show --numstat`). If the commit does not exist, ok is false and err is nil.
func SquashCommits ¶
SquashCommits soft-resets to mergeBase and commits with message. All changes since mergeBase are staged and committed as a single commit.
Types ¶
type CommitMeta ¶ added in v0.2.0
type CommitMeta struct {
SHA string
Subject string
AuthorName string
AuthorEmail string
AuthoredAt int64 // unix seconds
}
func ListCommitsRange ¶ added in v0.2.0
func ListCommitsRange(dir, from, to string) ([]CommitMeta, error)
ListCommitsRange returns commits reachable from to but not from from (from..to), ordered from oldest to newest.
type DiffFileStat ¶
type DiffFileStat struct {
Path string
Added int
Removed int
Binary bool
Status string // from `git diff --name-status` (e.g. A/M/D/R/C/T/U)
}
func DiffNumstat ¶
func DiffNumstat(dir, baseRef string) ([]DiffFileStat, error)
DiffNumstat returns per-file diff stats compared to baseRef. Includes both committed changes on the current branch and uncommitted changes.
func DiffNumstatRange ¶
func DiffNumstatRange(dir, baseRef, branchRef string) ([]DiffFileStat, error)
DiffNumstatRange returns per-file diff stats for base..branch.
type Error ¶ added in v0.2.0
Error is a structured git execution error that avoids leaking raw "exit status N" strings.
type IntegrationReason ¶
type IntegrationReason string
IntegrationReason describes why a branch is considered integrated into target.
const ( IntegratedSameCommit IntegrationReason = "same_commit" // Branch HEAD == target HEAD IntegratedAncestor IntegrationReason = "ancestor" // Branch is ancestor of target IntegratedNoAddedChanges IntegrationReason = "no_changes" // Three-dot diff is empty IntegratedTreesMatch IntegrationReason = "trees_match" // Same file tree, different history IntegratedMergeAddsNothing IntegrationReason = "merge_adds_nothing" // Merge simulation produces same tree )
func IsIntegrated ¶
func IsIntegrated(dir, branch, target string) IntegrationReason
IsIntegrated checks if branch's changes are integrated into target. Returns the reason if integrated, empty string if not. Checks are ordered by cost (cheapest first).