Documentation
¶
Overview ¶
Package git is the thin layer between hunk and the git binary.
ponytail: os/exec over a git library. This is eight commands; go-git is a large dependency, and manipulating the index by hand is exactly where a reimplementation of git goes wrong. hunk shells out only here — reading a diff and file/directory diffing stay git-free.
Index ¶
- func Available() bool
- type Commit
- type Repo
- func (r *Repo) ApplyCached(patch string) error
- func (r *Repo) Diff(ignoreWS bool, context int) (string, error)
- func (r *Repo) IsRepo() bool
- func (r *Repo) Log(n int, paths []string) ([]Commit, error)
- func (r *Repo) Root() (string, error)
- func (r *Repo) Show(sha string, ignoreWS bool, context int) (string, error)
- func (r *Repo) StageFiles(paths []string) error
- func (r *Repo) StagedDiff(paths []string, ignoreWS bool, context int) (string, error)
- func (r *Repo) StagedPaths() ([]string, error)
- func (r *Repo) UnapplyCached(patch string) error
- func (r *Repo) UnstageFiles(paths []string) error
- func (r *Repo) UnstagedPaths() ([]string, error)
- func (r *Repo) Untracked() ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Commit ¶
type Commit struct {
SHA string // full hash, what Show is called with
Short string // abbreviated, what the sidebar shows
Author string
Rel string // relative to now, e.g. "3 days ago"
Subject string
}
Commit is one entry of the history, as the log panel shows it.
type Repo ¶
type Repo struct {
// Dir is where git commands run. Empty means the current directory.
Dir string
}
Repo is a git repository hunk is reviewing.
func (*Repo) ApplyCached ¶
ApplyCached stages a patch.
--cached means only the index is written: no working-tree file is created, modified, or removed by this call, so an unwanted stage is undone with "git restore --staged". --recount lets git fix up the @@ line counts, which is what makes it safe to emit selected hunks verbatim.
func (*Repo) Diff ¶
Diff returns the unstaged changes: the working tree against the index. This is the same set of changes "git add -p" walks you through. ignoreWS drops whitespace-only changes (git's -w); context is the lines shown around each hunk (git's -U).
func (*Repo) Log ¶
Log reads the n most recent commits, newest first. paths, when given, narrows the history to commits that touch them.
A repository with no commits yet has an empty history, not a broken one, so an unborn HEAD returns no commits rather than git's "does not have any commits yet" error.
func (*Repo) Root ¶ added in v0.2.0
Root is the top of the working tree, which the paths in a diff are relative to.
func (*Repo) Show ¶
Show returns one commit's changes as unified diff text, with the commit message stripped so it parses like every other source hunk reads.
--first-parent -m is what gives a merge commit a diff at all: without it, "git show" prints a merge's header and nothing else.
func (*Repo) StageFiles ¶
StageFiles stages whole files. Used for untracked files, which have no hunks to choose between.
func (*Repo) StagedDiff ¶
StagedDiff returns the staged diff (index against HEAD) for the given paths. It is what lets a fully staged file stay on screen with its changes visible.
func (*Repo) StagedPaths ¶
StagedPaths lists files with content staged in the index against HEAD.
func (*Repo) UnapplyCached ¶
UnapplyCached reverses a patch that was staged with ApplyCached, taking exactly those changes back out of the index and nothing else. It is the undo for a hunk stage.
func (*Repo) UnstageFiles ¶
UnstageFiles removes whole files from the index, the undo for StageFiles.
func (*Repo) UnstagedPaths ¶
UnstagedPaths lists files with changes in the working tree that are not yet staged — the files Diff would show, by name.