git

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyTree = "4b825dc642cb6eb9a060e54bf899d69f82cf7207"

EmptyTree is git's well-known empty-tree object, used as the base when diffing a root commit (which has no parent).

Variables

This section is empty.

Functions

func DiffTargets

func DiffTargets(args []string) (base, target string, err error)

func Paths added in v0.3.0

func Paths(files []ChangedFile) []string

Paths returns just the paths of the changed files.

func SortByPath added in v0.4.0

func SortByPath(files []ChangedFile)

SortByPath orders changed files by path, for a stable listing (go-git returns map order). Callers that present a file list sort through this so the ordering rule lives in one place.

func StatusChar

func StatusChar(status string) string

Types

type ChangedFile

type ChangedFile struct {
	Path    string `json:"path"`
	Status  string `json:"status"`
	Added   int    `json:"added"`
	Deleted int    `json:"deleted"`
}

func FilterByPaths

func FilterByPaths(files []ChangedFile, paths []string) []ChangedFile

type CommitInfo

type CommitInfo struct {
	Hash    string `json:"hash"`
	Author  string `json:"author"`
	Date    string `json:"date"`
	Message string `json:"message"`
	Body    string `json:"body,omitempty"`
}

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

func OpenRepo

func OpenRepo() (*Repo, error)

func (*Repo) BlobHashes added in v0.5.0

func (r *Repo) BlobHashes(paths []string) map[string]string

BlobHashes returns the git blob hash of each path's current working-tree content, in one subprocess. Paths that don't exist on disk (a deleted file, a directory) are omitted — there's no content to hash.

func (*Repo) ChangedFiles

func (r *Repo) ChangedFiles(staged bool) ([]ChangedFile, error)

ChangedFiles lists the working-tree files with a staged change (staged=true) or an unstaged/untracked change (staged=false), derived from `git status`.

func (*Repo) CurrentBranch added in v0.3.1

func (r *Repo) CurrentBranch() string

CurrentBranch returns the checked-out branch name, the short commit hash when HEAD is detached, or "" if it can't be determined. go-git can't read HEAD in a linked worktree (go-git#1842), so any go-git failure falls back to shelling — the same try-go-git-then-shell pattern the log reads use.

func (*Repo) DiffBetweenCommits

func (r *Repo) DiffBetweenCommits(baseRef, targetRef string) ([]ChangedFile, error)

DiffBetweenCommits lists the files changed between two refs. It shells out to git: a tree-to-tree diff is fast (it never walks the worktree) and git resolves refs correctly in every layout, including the linked worktrees where go-git can't (go-git#1842). It uses two args (not the `a..b` range, which rejects a tree on either side); for a root commit (base = the empty tree, whose object may not be in the odb) it uses `diff-tree --root` against target.

--no-renames keeps a rename as a delete + an add (like statusFiles), so a renamed file in a commit drilldown renders correctly instead of as a whole addition — the new path doesn't exist at the base, so the diff engine would extract a /dev/null old side for it.

func (*Repo) GitPath added in v0.5.0

func (r *Repo) GitPath(rel string) (string, error)

GitPath resolves a path inside the git directory (e.g. "rift/reviewed.json"), honoring linked-worktree layouts where the gitdir lives elsewhere. It does not create anything — callers MkdirAll the parent before writing.

func (*Repo) ListStashes

func (r *Repo) ListStashes() ([]StashEntry, error)

func (*Repo) Log

func (r *Repo) Log(ref string, maxCount int, paths []string) ([]CommitInfo, error)

func (*Repo) LogAll

func (r *Repo) LogAll(maxCount int, paths []string) ([]CommitInfo, error)

func (*Repo) Root

func (r *Repo) Root() string

func (*Repo) Stage

func (r *Repo) Stage(paths ...string) error

func (*Repo) StageHunk

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

func (*Repo) StatusFiles

func (r *Repo) StatusFiles() ([]StatusFile, error)

func (*Repo) Unstage

func (r *Repo) Unstage(paths ...string) error

func (*Repo) UnstageHunk

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

type StashEntry

type StashEntry struct {
	Index   int    `json:"index"`
	Branch  string `json:"branch"`
	Message string `json:"message"`
	Date    string `json:"date"`
}

type StatusFile

type StatusFile struct {
	Path           string `json:"path"`
	StagingStatus  string `json:"staging_status"`
	WorktreeStatus string `json:"worktree_status"`
}

Jump to

Keyboard shortcuts

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