git

package
v0.0.0-...-6acd4b1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git provides wrappers around git porcelain commands. All operations run git as a subprocess; no CGO, no libgit2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorStat

type AuthorStat struct {
	Name    string
	Email   string
	Commits int64
}

AuthorStat holds shortlog stats for one author.

type LogEntry

type LogEntry struct {
	Hash    string
	Author  string
	Email   string
	Date    string // ISO 8601
	Subject string
	Added   int64
	Deleted int64
}

LogEntry is a single entry from git log --numstat.

type Repo

type Repo struct {
	Root   string // absolute path to the repo root
	GitDir string // path to .git dir or file
}

Repo represents a git repository.

func Discover

func Discover(dir string) (*Repo, error)

Discover finds the git repository root starting from dir. Equivalent to `git rev-parse --show-toplevel`.

func (*Repo) BlameLines

func (r *Repo) BlameLines(file, ref string) (map[string]int64, error)

BlameLines runs git blame --porcelain for a file and returns per-author line counts.

func (*Repo) Branches

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

Branches returns the list of local branch names.

func (*Repo) CommitAtDate

func (r *Repo) CommitAtDate(date string) (string, error)

CommitAtDate finds the closest commit SHA at or before the given date.

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch() string

CurrentBranch returns the current branch name, or "HEAD" if detached.

func (*Repo) HEAD

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

HEAD returns the current HEAD commit SHA.

func (*Repo) IsClean

func (r *Repo) IsClean() (bool, error)

IsClean returns true if the working tree and index have no uncommitted changes.

func (*Repo) LastCommitTime

func (r *Repo) LastCommitTime() string

LastCommitTime returns the relative time of the last commit (e.g. "3 hours ago").

func (*Repo) ListFiles

func (r *Repo) ListFiles(ref string, excludePatterns []string) ([]string, error)

ListFiles returns the list of git-tracked files for the given ref. If ref is empty, uses the index (working tree tracked files). It respects .gitignore and --exclude patterns if running against the working tree.

func (*Repo) Log

func (r *Repo) Log(ref string, limit int, since, until string) ([]LogEntry, error)

Log returns log entries with numstat for the given ref range.

func (*Repo) RevParse

func (r *Repo) RevParse(ref string) (string, error)

RevParse resolves a ref to a full commit SHA.

func (*Repo) Shortlog

func (r *Repo) Shortlog(ref string) ([]AuthorStat, error)

Shortlog returns per-author commit and line counts.

func (*Repo) TreeSHA

func (r *Repo) TreeSHA(ref string) (string, error)

TreeSHA returns the tree SHA for a given ref (or HEAD if ref is empty).

Jump to

Keyboard shortcuts

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