Documentation
¶
Overview ¶
Package git wraps the handful of git commands live-pr needs by shelling out, rather than pulling in a full git library.
Index ¶
- func CheckoutPullHead(branch string) error
- func CommonDir(dir string) (string, error)
- func CurrentBranch() (string, error)
- func DefaultBase() string
- func FetchPull(number int, base string) (string, string, error)
- func FileDiffRange(base, head string, paths ...string) (string, error)
- func HasChanges(base, head string) (bool, error)
- func HasUncommittedChanges() (bool, error)
- func IsAncestor(ancestor, descendant string) (bool, error)
- func MergeBase(base, head string) (string, error)
- func Push(branch string) error
- func RepoRoot() (string, error)
- func ResolveBase(base string) string
- func Revision(rev string) (string, error)
- func RevisionDistance(local, remote string) (ahead, behind int, err error)
- func Show(sha string) (string, error)
- type ChangeStats
- type ChangedFile
- type Commit
- type LocalSnapshot
- type LocalState
- type MergeReadiness
- type RevisionRelation
- type WorktreeSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckoutPullHead ¶ added in v0.7.0
CheckoutPullHead checks out the head branch of a same-repository pull request with plain git, mirroring gh pr checkout's non-fork path: fetch the branch from origin, then switch to a local tracking branch, fast-forwarding one that already exists (a diverged branch fails the same way it does under gh). Fork heads need gh's cross-repository remote wiring and must not come here.
func CommonDir ¶ added in v0.5.5
CommonDir returns the absolute path of the repository's common .git directory for the checkout at dir. Linked worktrees share it with their main checkout, so it identifies the repository across worktrees.
func CurrentBranch ¶
CurrentBranch returns the checked-out branch name (e.g. "main", "feature/x").
func DefaultBase ¶
func DefaultBase() string
DefaultBase returns the branch to compare against: the remote's default (origin/HEAD, e.g. "origin/main") when known, else a local main/master, falling back to "main".
func FetchPull ¶
FetchPull fetches a GitHub pull ref and its base without changing HEAD, the index, or the worktree. It returns the namespaced local head ref.
func FileDiffRange ¶
FileDiffRange returns the colorized base...head patch for selected paths. An empty head compares through the working tree and includes selected untracked files without changing the index.
func HasChanges ¶
HasChanges reports whether base...head contains any changed paths.
func HasUncommittedChanges ¶
HasUncommittedChanges reports whether the index, worktree, or untracked files differ from HEAD.
func IsAncestor ¶ added in v0.9.0
IsAncestor reports whether ancestor is reachable from descendant.
func Push ¶
Push pushes the branch to origin, setting upstream. A stalled SSH/HTTPS transport must not hang the caller forever, so the push is bounded; the limit is longer than FetchPull's because a push carries data up.
func ResolveBase ¶
ResolveBase turns a GitHub base name into the freshest local Git revision, preferring its origin remote-tracking ref when available.
func RevisionDistance ¶ added in v0.9.0
CompareRevisions classifies local relative to remote by graph reachability. RevisionDistance returns commits unique to local and remote.
Types ¶
type ChangeStats ¶
type ChangeStats struct {
Files, Additions, Deletions int
}
ChangeStats summarizes a diff range for PR list metadata.
func DiffStats ¶
func DiffStats(base, head string) (ChangeStats, error)
DiffStats returns file and line counts for the given range. An empty head compares the working tree against base. Binary files count toward Files but not line totals.
type ChangedFile ¶
type ChangedFile struct {
Status string
Path string
OldPath string
// Fingerprint identifies this file's diff content. It changes only when
// this file's own diff changes, so reviewed marks survive commits that
// touch other files.
Fingerprint string
}
ChangedFile is one entry in base...HEAD.
func ChangedFilesRange ¶
func ChangedFilesRange(base, head string) ([]ChangedFile, error)
ChangedFilesRange returns changed paths in the given range. An empty head compares the working tree against base and includes untracked files.
type Commit ¶
Commit is a git commit reduced to what the timeline needs.
func CommitsRange ¶
CommitsRange returns commits in base..head, oldest first.
type LocalSnapshot ¶ added in v0.9.0
type LocalSnapshot struct {
State LocalState
Worktree WorktreeSummary
}
func CurrentLocalSnapshot ¶ added in v0.9.0
func CurrentLocalSnapshot() (LocalSnapshot, error)
CurrentLocalSnapshot derives branch, fingerprint, and worktree counts from one porcelain-v2 scan.
type LocalState ¶ added in v0.9.0
LocalState identifies the checked-out branch and every local Git input that can change the review (HEAD, index, worktree, and untracked paths).
func CurrentLocalState ¶ added in v0.9.0
func CurrentLocalState() (LocalState, error)
type MergeReadiness ¶ added in v0.2.0
MergeReadiness describes how far head trails base and which paths conflict.
func CheckMergeReadiness ¶ added in v0.2.0
func CheckMergeReadiness(base, head string) (MergeReadiness, error)
CheckMergeReadiness simulates merging head into base without touching HEAD, the index, or the worktree.
type RevisionRelation ¶ added in v0.9.0
type RevisionRelation uint8
RevisionRelation describes local relative to a published revision.
const ( RevisionUnknown RevisionRelation = iota RevisionSynced RevisionLocalAhead RevisionRemoteAhead RevisionDiverged )
func CompareRevisions ¶ added in v0.9.0
func CompareRevisions(local, remote string) (RevisionRelation, error)
type WorktreeSummary ¶ added in v0.9.0
type WorktreeSummary struct {
Staged, Unstaged, Untracked int
}
func WorktreeStatus ¶ added in v0.9.0
func WorktreeStatus() (WorktreeSummary, error)
WorktreeStatus summarizes index, worktree, and untracked entries.
func (WorktreeSummary) Total ¶ added in v0.9.0
func (s WorktreeSummary) Total() int