git

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountLines

func CountLines(out string) int

CountLines counts non-empty lines, used for git stash list.

func Diff added in v0.3.0

func Diff(root string, f FileStatus) (string, error)

Diff returns the patch for one changed path. When both the index and the working tree changed it joins the staged and unstaged diffs, and for an untracked file it synthesises a new-file patch.

func FormatWhen

func FormatWhen(t, now time.Time) string

FormatWhen renders a short relative time, or a month-day date after two weeks.

func Show

func Show(root, hash string) (string, error)

Show returns a commit summary suitable for the preview pane.

Types

type Commit

type Commit struct {
	Hash    string
	Subject string
	When    time.Time
}

Commit is one git log row.

func ParseLog

func ParseLog(out string) ([]Commit, error)

ParseLog parses lines of hash, unix seconds, and subject separated by tabs.

type FileStatus added in v0.3.0

type FileStatus struct {
	Path      string
	OrigPath  string
	Index     byte
	Worktree  byte
	Untracked bool
	Unmerged  bool
}

FileStatus is one changed path. Index is the staged code and Worktree is the unstaged code, using the porcelain-v2 letters ('.' means unchanged).

func (FileStatus) Code added in v0.3.0

func (f FileStatus) Code() string

Code renders the two status columns, for example "M ", " M", or "??".

func (FileStatus) Staged added in v0.3.0

func (f FileStatus) Staged() bool

Staged reports whether the index differs from HEAD.

func (FileStatus) Unstaged added in v0.3.0

func (f FileStatus) Unstaged() bool

Unstaged reports whether the working tree differs from the index.

type Snapshot

type Snapshot struct {
	Repo    bool
	Status  Status
	Commits []Commit
	Err     string
}

Snapshot is a point-in-time read of a working tree.

func Load

func Load(root string) Snapshot

Load runs git in root. Repo is false when root is not a repository.

type Status

type Status struct {
	Branch   string
	Upstream string
	Ahead    int
	Behind   int
	Staged   int
	Unstaged int
	Stash    int
	Detached bool
	Dirty    map[string]struct{}
	// Files lists each changed path in the order git reports it.
	Files []FileStatus
}

Status is a branch and worktree summary from git status --porcelain=v2 --branch. Untracked paths count as unstaged.

func ParseStatus

func ParseStatus(out string) (Status, error)

ParseStatus parses porcelain v2 output that includes the branch header.

Jump to

Keyboard shortcuts

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