Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommitStaged added in v0.26.0

func CommitStaged(dir, msg string) error

CommitStaged commits the currently staged changes with the given message. It uses a local identity override so it works in repos without user.name/ user.email configured. Returns an error when nothing is staged.

func DiffFile added in v0.26.0

func DiffFile(dir, path string, staged bool) (string, error)

DiffFile returns the raw unified diff for path. When staged is true it diffs the index (cached) instead of the working tree. Returns "" when the file has no changes at the requested level. Uses --no-color.

Untracked files (git status "??") are diffed with `git diff --no-index /dev/null -- path` so that a brand-new file renders as an all-addition hunk instead of the empty string plain `git diff` returns for untracked paths. Staged untracked files are handled by the normal --cached path.

func HasStaged added in v0.26.0

func HasStaged(dir string) bool

HasStaged reports whether the index has any staged changes.

func IsRepo added in v0.26.0

func IsRepo(dir string) bool

IsRepo reports whether dir is inside a git work tree.

func ShowCommit added in v0.26.0

func ShowCommit(dir, sha string) (string, error)

ShowCommit returns the full unified diff for the given commit (raw text from `git show --no-color`).

func Stage added in v0.26.0

func Stage(dir string, paths []string) error

Stage adds the given paths to the index (git add -- <paths...>). It uses explicit paths only — never -A — so the caller controls scope. Empty paths is a no-op.

func Unstage added in v0.26.0

func Unstage(dir string, paths []string) error

Unstage removes the given paths from the index (git reset HEAD -- <paths...>). Empty paths is a no-op.

Types

type Commit added in v0.26.0

type Commit struct {
	SHA     string `json:"sha"`
	Short   string `json:"short"`
	Message string `json:"message"` // subject line only
	Author  string `json:"author"`
	Time    string `json:"time"` // ISO 8601
}

Commit is one entry from `git log --format=...`.

func RecentCommits added in v0.26.0

func RecentCommits(dir string, n int) ([]Commit, error)

RecentCommits returns the last n commits (default 20 when n <= 0) as Commit entries. Returns nil, nil when dir is not a git repository.

type FileStatus added in v0.26.0

type FileStatus struct {
	Path   string `json:"path"`   // workspace-relative
	X      string `json:"x"`      // index/staged state code, e.g. "M", "A", " ", "?"
	Y      string `json:"y"`      // worktree state code
	Staged bool   `json:"staged"` // true when X is non-blank and not "?"
}

FileStatus is one entry from `git status --porcelain`.

func Status added in v0.26.0

func Status(dir string) ([]FileStatus, error)

Status returns the working-tree status of dir as a list of FileStatus entries (one per changed file). Returns nil, nil when the tree is clean. Returns nil, nil (not an error) when dir is not a git repository.

Jump to

Keyboard shortcuts

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