git

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available reports whether the git binary is on PATH at all.

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

func (r *Repo) ApplyCached(patch string) error

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

func (r *Repo) Diff(ignoreWS bool, context int) (string, error)

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) IsRepo

func (r *Repo) IsRepo() bool

IsRepo reports whether we are inside a git working tree.

func (*Repo) Log

func (r *Repo) Log(n int, paths []string) ([]Commit, error)

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

func (r *Repo) Root() (string, error)

Root is the top of the working tree, which the paths in a diff are relative to.

func (*Repo) Show

func (r *Repo) Show(sha string, ignoreWS bool, context int) (string, error)

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

func (r *Repo) StageFiles(paths []string) error

StageFiles stages whole files. Used for untracked files, which have no hunks to choose between.

func (*Repo) StagedDiff

func (r *Repo) StagedDiff(paths []string, ignoreWS bool, context int) (string, error)

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

func (r *Repo) StagedPaths() ([]string, error)

StagedPaths lists files with content staged in the index against HEAD.

func (*Repo) UnapplyCached

func (r *Repo) UnapplyCached(patch string) error

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

func (r *Repo) UnstageFiles(paths []string) error

UnstageFiles removes whole files from the index, the undo for StageFiles.

func (*Repo) UnstagedPaths

func (r *Repo) UnstagedPaths() ([]string, error)

UnstagedPaths lists files with changes in the working tree that are not yet staged — the files Diff would show, by name.

func (*Repo) Untracked

func (r *Repo) Untracked() ([]string, error)

Untracked lists files git does not know about yet, honouring .gitignore.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL