Documentation
¶
Index ¶
- Constants
- func DiffTargets(args []string) (base, target string, err error)
- func Paths(files []ChangedFile) []string
- func SortByPath(files []ChangedFile)
- func StatusChar(status string) string
- type ChangedFile
- type CommitInfo
- type Repo
- func (r *Repo) BlobHashes(paths []string) map[string]string
- func (r *Repo) ChangedFiles(staged bool) ([]ChangedFile, error)
- func (r *Repo) CurrentBranch() string
- func (r *Repo) DiffBetweenCommits(baseRef, targetRef string) ([]ChangedFile, error)
- func (r *Repo) GitPath(rel string) (string, error)
- func (r *Repo) ListStashes() ([]StashEntry, error)
- func (r *Repo) Log(ref string, maxCount int, paths []string) ([]CommitInfo, error)
- func (r *Repo) LogAll(maxCount int, paths []string) ([]CommitInfo, error)
- func (r *Repo) Root() string
- func (r *Repo) Stage(paths ...string) error
- func (r *Repo) StageHunk(patch string) error
- func (r *Repo) StatusFiles() ([]StatusFile, error)
- func (r *Repo) Unstage(paths ...string) error
- func (r *Repo) UnstageHunk(patch string) error
- type StashEntry
- type StatusFile
Constants ¶
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 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 ¶
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 Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) BlobHashes ¶ added in v0.5.0
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
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
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) StatusFiles ¶
func (r *Repo) StatusFiles() ([]StatusFile, error)