Documentation
¶
Index ¶
- Constants
- func CurrentBranchName() string
- func CurrentRef() (string, error)
- func DefaultBranch() (string, error)
- func DiscardFile(path string, status FileStatus, staged bool) error
- func DiscardHunk(path string, status FileStatus, h Hunk) error
- func EnableUntrackedCache() error
- func Format(d *Diff) string
- func FormatGutter(l Line) string
- func FormatHunks(d *Diff) string
- func FormatLine(l Line) string
- func GitDir() (string, error)
- func HasCommits() bool
- func HunkContextText(header string) string
- func HunkHeaderText(h Hunk) string
- func HunkPatch(path string, status FileStatus, h Hunk) string
- func HunkSourceLabel(s HunkSource) string
- func InvalidateUntrackedCache()
- func IsGitRepo() bool
- func IsOnDefaultBranch() (bool, error)
- func MergeBase(branch string) (string, error)
- func RawDiff(mergeBase string, contextLines int) (string, error)
- func RawDiffBetween(from, to string, contextLines int) (string, error)
- func RawDiffBetweenIgnoreWhitespace(from, to string, contextLines int) (string, error)
- func RemoteName() string
- func RepoRoot() (string, error)
- func StageFile(path string) error
- func StageHunk(path string, status FileStatus, h Hunk) error
- func StagedDiff(contextLines int) (string, error)
- func StagedDiffIgnoreWhitespace(contextLines int) (string, error)
- func StatusFingerprint() (string, error)
- func TestUntrackedCacheSupport() error
- func UnstageFile(path string) error
- func UnstageHunk(path string, status FileStatus, h Hunk) error
- func UnstagedDiff(contextLines int) (string, error)
- func UnstagedDiffIgnoreWhitespace(contextLines int) (string, error)
- func UntrackedCacheEnabled() bool
- type Diff
- func BranchDiff(contextLines int) (*Diff, error)
- func BranchDiffOptions(contextLines int, hideWhitespace bool) (*Diff, error)
- func GetDiff() (*Diff, error)
- func Parse(raw string) *Diff
- func StagedOnlyDiff(contextLines int) (*Diff, error)
- func StagedOnlyDiffOptions(contextLines int, hideWhitespace bool) (*Diff, error)
- func UnstagedOnlyDiff(contextLines int) (*Diff, error)
- func UnstagedOnlyDiffOptions(contextLines int, hideWhitespace bool) (*Diff, error)
- func WorkingTreeDiff(contextLines int) (*Diff, error)
- func WorkingTreeDiffOptions(contextLines int, hideWhitespace bool) (*Diff, error)
- type FileDiff
- type FileStatus
- type Hunk
- type HunkSource
- type Line
- type LineType
Constants ¶
const DefaultContextLines = 3
DefaultContextLines is the default number of context lines in unified diffs.
Variables ¶
This section is empty.
Functions ¶
func CurrentBranchName ¶
func CurrentBranchName() string
CurrentBranchName returns the name of the currently checked out branch, or "" if in detached HEAD state.
func CurrentRef ¶
CurrentRef returns the current HEAD commit hash.
func DefaultBranch ¶
DefaultBranch detects the default branch of the repository.
func DiscardFile ¶
func DiscardFile(path string, status FileStatus, staged bool) error
DiscardFile discards all changes to a file. For untracked files, removes the file. If staged is true, unstages first, then reverts the working tree.
func DiscardHunk ¶
func DiscardHunk(path string, status FileStatus, h Hunk) error
DiscardHunk discards a hunk by reverting it from the working tree. For staged hunks, it first unstages, then reverts the working tree.
func EnableUntrackedCache ¶ added in v0.4.0
func EnableUntrackedCache() error
EnableUntrackedCache sets core.untrackedCache=true in the current repo's local config. Local scope, not --global — we never modify the user's global git config implicitly.
func FormatGutter ¶ added in v0.4.0
FormatGutter returns the 6-char line-number gutter shown next to each diff line: 5-char right-aligned number + 1 space, or 6 spaces for non-content lines (hunk headers, blank separators). Removed lines use OldNum; added and context lines use NewNum.
func FormatHunks ¶ added in v0.4.0
FormatHunks renders a Diff in the same shape the TUI shows on screen — file path header, hunk header with source label + function context, then each line prefixed by a 6-char line-number gutter and a +/-/space marker. No ANSI colors. Useful for non-interactive debugging via `revise diff --hunks`.
func FormatLine ¶
FormatLine returns a formatted string for a line with gutter.
func GitDir ¶ added in v0.4.0
GitDir returns the absolute path to the git directory for the current working tree. In a worktree this is `<main-repo>/.git/worktrees/<name>/`, not the worktree's `.git` file. Used by fswatch to monitor index/HEAD changes (per-worktree, not the main repo's).
func HunkContextText ¶ added in v0.4.0
HunkContextText extracts the trailing context from a unified-diff hunk header (`@@ -x,y +a,b @@ trailing context`). Returns "" if the header has no trailing context.
func HunkHeaderText ¶ added in v0.4.0
HunkHeaderText composes the hunk header the way it appears in the TUI: optional `[source]` tag (branch/staged/unstaged) + the function-context trailer from the `@@ -x,y +a,b @@ context` line. Returns "" when neither is available (e.g. file review mode).
func HunkPatch ¶
func HunkPatch(path string, status FileStatus, h Hunk) string
HunkPatch reconstructs a unified diff patch for a single hunk, suitable for piping to `git apply`.
func HunkSourceLabel ¶ added in v0.4.0
func HunkSourceLabel(s HunkSource) string
HunkSourceLabel returns the lowercase label for a HunkSource ("branch", "staged", "unstaged"), or "" for the zero value.
func InvalidateUntrackedCache ¶
func InvalidateUntrackedCache()
InvalidateUntrackedCache forces the next UntrackedFiles call to re-read files.
func IsGitRepo ¶
func IsGitRepo() bool
IsGitRepo checks if the current directory is inside a git repository.
func IsOnDefaultBranch ¶
IsOnDefaultBranch returns true if the current HEAD is at the merge-base with the default branch AND up to date with the remote tracking branch. Returns false when on a feature branch (merge-base != HEAD) or when on the default branch but the remote has diverged (useful for reviewing incoming/outgoing changes via branch mode).
func RawDiffBetween ¶
RawDiffBetween returns the raw unified diff between two refs.
func RawDiffBetweenIgnoreWhitespace ¶
RawDiffBetweenIgnoreWhitespace returns the raw unified diff between two refs, ignoring whitespace.
func RemoteName ¶
func RemoteName() string
RemoteName returns the name of the tracking remote. It prefers "origin" if present, otherwise returns the first configured remote. Returns an empty string if there are no remotes.
func RepoRoot ¶
RepoRoot returns the absolute path to the top-level directory of the git repository.
func StageHunk ¶
func StageHunk(path string, status FileStatus, h Hunk) error
StageHunk stages a single hunk by applying the patch to the index. Untracked files don't exist in the index, so git apply --cached fails; fall back to git add for those.
func StagedDiff ¶
StagedDiff returns the raw diff of staged changes.
func StagedDiffIgnoreWhitespace ¶
StagedDiffIgnoreWhitespace returns the raw diff of staged changes, ignoring whitespace.
func StatusFingerprint ¶
StatusFingerprint returns a string that changes whenever the working tree or index changes. It combines `git status --porcelain` (file-level status including untracked) with mtimes of dirty working tree files for content-level sensitivity.
func TestUntrackedCacheSupport ¶ added in v0.4.0
func TestUntrackedCacheSupport() error
TestUntrackedCacheSupport runs git's built-in filesystem self-test. Returns nil if the filesystem reliably updates directory mtimes (required for the untracked cache), or an error otherwise. The test has small, transient filesystem side effects and should be treated as a one-shot check.
func UnstageFile ¶
UnstageFile unstages an entire file (keeps working tree changes).
func UnstageHunk ¶
func UnstageHunk(path string, status FileStatus, h Hunk) error
UnstageHunk unstages a single hunk by reverse-applying the patch from the index.
func UnstagedDiff ¶
UnstagedDiff returns the raw diff of unstaged changes.
func UnstagedDiffIgnoreWhitespace ¶
UnstagedDiffIgnoreWhitespace returns the raw diff of unstaged changes, ignoring whitespace.
func UntrackedCacheEnabled ¶ added in v0.4.0
func UntrackedCacheEnabled() bool
UntrackedCacheEnabled reports whether git's core.untrackedCache is enabled for the current repo. A missing config key is treated as not enabled. The untracked cache speeds up `git status` by caching directory mtimes — enabling it makes revise's polling loop noticeably faster on large repos.
Types ¶
type Diff ¶
type Diff struct {
Files []FileDiff
}
Diff represents the complete diff output.
func BranchDiff ¶
BranchDiff returns the merge-base diff merged with all working tree changes. This is the broadest view — committed + staged + unstaged + untracked. On the default branch behind the remote, it shows the remote's changes. The working tree diff runs concurrently with the branch diff computation.
func BranchDiffOptions ¶
BranchDiffOptions returns BranchDiff with optional whitespace ignoring. The working tree diff runs concurrently with the branch diff computation.
func GetDiff ¶
GetDiff returns a parsed Diff for the current branch vs the default branch. If on the default branch, it shows working tree changes (staged + unstaged). Otherwise it shows committed changes vs merge-base plus working tree changes. In a repo with no commits, IsOnDefaultBranch returns true and the working tree diff still surfaces staged + untracked files via the empty-tree implicit base used by `git diff --cached`.
func StagedOnlyDiff ¶
StagedOnlyDiff returns only staged changes.
func StagedOnlyDiffOptions ¶
StagedOnlyDiffOptions returns only staged changes, optionally ignoring whitespace.
func UnstagedOnlyDiff ¶
UnstagedOnlyDiff returns unstaged changes + untracked files.
func UnstagedOnlyDiffOptions ¶
UnstagedOnlyDiffOptions returns unstaged changes + untracked files, optionally ignoring whitespace.
func WorkingTreeDiff ¶
WorkingTreeDiff returns staged + unstaged + untracked changes.
type FileDiff ¶
type FileDiff struct {
Path string
OldPath string // for renames
Status FileStatus
IsBinary bool
Hunks []Hunk
}
FileDiff represents the diff for a single file.
func UntrackedFiles ¶
UntrackedFiles returns synthetic FileDiff entries for untracked files. Results are cached to avoid re-reading file contents when only context lines change (the bottleneck identified in issue #35).
type FileStatus ¶
type FileStatus string
FileStatus represents the type of change.
const ( StatusModified FileStatus = "M" StatusAdded FileStatus = "A" StatusDeleted FileStatus = "D" StatusRenamed FileStatus = "R" StatusUntracked FileStatus = "?" )
type Hunk ¶
type Hunk struct {
OldStart int
OldCount int
NewStart int
NewCount int
Header string // the @@ line
Source HunkSource
Lines []Line
}
Hunk represents a single diff hunk.
type HunkSource ¶
type HunkSource string
HunkSource identifies where a hunk came from.
const ( SourceBranch HunkSource = "Branch" SourceStaged HunkSource = "Staged" SourceUnstaged HunkSource = "Unstaged" )