git

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package git wraps the local git CLI for nook's git pane.

Surfaces:

  • Status: `git status --porcelain=v1 --branch -z` parsed into entries.
  • Diff: `git diff -- <path>` and `git diff --cached -- <path>` for inspection.
  • Stage/unstage: `git add` / `git reset HEAD -- <path>`.
  • Commit: `git commit -m <msg>` (signed if config gpg.sign or commit.gpgsign set).

The Pane renders a two-column status (staged + unstaged), a commit-message editor, and emits messages so the host can route to a diff buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit(ctx context.Context, root, msg string) (string, error)

Commit runs `git commit -m <msg>` and returns the new SHA.

func Diff

func Diff(ctx context.Context, root, path string, staged bool) (string, error)

Diff returns `git diff [-- cached] -- <path>`.

func Stage

func Stage(ctx context.Context, root, path string) error

Stage runs `git add -- <path>`.

func Unstage

func Unstage(ctx context.Context, root, path string) error

Unstage runs `git reset HEAD -- <path>`.

Types

type CancelMsg

type CancelMsg struct{}

CancelMsg is emitted when the user presses Esc.

type CommitMsg

type CommitMsg struct {
	SHA string // empty on error
	Err error
}

CommitMsg is emitted by CommitCmd.

type DiffMsg

type DiffMsg struct {
	Path   string
	Staged bool
	Body   string
	Err    error
}

DiffMsg is emitted by DiffCmd; the host renders this in a side pane.

type Entry

type Entry struct {
	Index    StatusCode // staged side (X)
	WorkTree StatusCode // unstaged side (Y)
	Path     string
	OrigPath string // populated on rename
}

Entry is one row in `git status --porcelain`.

func (Entry) Staged

func (e Entry) Staged() bool

Staged reports whether the index column shows a staged change.

func (Entry) Unstaged

func (e Entry) Unstaged() bool

Unstaged reports whether the working-tree column shows an unstaged change.

func (Entry) Untracked

func (e Entry) Untracked() bool

Untracked reports whether the file is untracked.

type Pane

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

Pane is the git status UI.

func NewPane

func NewPane(t theme.Theme, root string) Pane

NewPane constructs an empty pane rooted at root.

func (Pane) Blur

func (p Pane) Blur() Pane

Blur sets focused=false and exits commit editing.

func (Pane) CommitMessage

func (p Pane) CommitMessage() string

CommitMessage returns the current draft message.

func (Pane) Editing

func (p Pane) Editing() bool

Editing reports whether the commit-message editor has focus.

func (Pane) Focus

func (p Pane) Focus() Pane

Focus sets focused=true.

func (Pane) Focused

func (p Pane) Focused() bool

Focused reports whether the pane has keyboard focus.

func (Pane) Selected

func (p Pane) Selected() (Entry, bool)

Selected returns the currently highlighted entry (if any).

func (Pane) SetStatus

func (p Pane) SetStatus(s Status) Pane

SetStatus replaces the pane's status snapshot.

func (Pane) SetTheme added in v0.38.0

func (p Pane) SetTheme(t theme.Theme) Pane

SetTheme swaps the palette used for status rows, the branch chip, stage markers, and the commit editor. Next View() picks up the new colors.

func (Pane) Update

func (p Pane) Update(msg tea.Msg) (Pane, tea.Cmd)

Update routes a key event. Returns one of: nil, CancelMsg, or a tea.Cmd the host should execute (Stage/Unstage/Commit/Diff).

Keymap (when not editing):

j / down     move cursor
k / up       move cursor
enter        request diff
s            stage
u            unstage
c            enter commit-message editor
esc          emit CancelMsg

Keymap (when editing):

ctrl+enter   commit
esc          exit editor
chars        append to message
backspace    delete last char

func (Pane) View

func (p Pane) View() string

View renders the pane.

func (Pane) WithSize

func (p Pane) WithSize(w, h int) Pane

WithSize sets pane dimensions.

type StagedMsg

type StagedMsg struct {
	Path string
	Err  error
}

StagedMsg is emitted after `git add -- <path>`.

type Status

type Status struct {
	Branch  string
	Ahead   int
	Behind  int
	Entries []Entry
}

Status is the parsed result of `git status`.

func RunStatus

func RunStatus(ctx context.Context, root string) (Status, error)

Status runs `git status --porcelain=v1 --branch -z` and parses the output.

type StatusCode

type StatusCode rune

StatusCode is the porcelain v1 single-letter status for one side (staged X or unstaged Y).

const (
	StatusUnmodified StatusCode = ' '
	StatusModified   StatusCode = 'M'
	StatusAdded      StatusCode = 'A'
	StatusDeleted    StatusCode = 'D'
	StatusRenamed    StatusCode = 'R'
	StatusCopied     StatusCode = 'C'
	StatusUntracked  StatusCode = '?'
	StatusIgnored    StatusCode = '!'
	StatusConflicted StatusCode = 'U'
)

type StatusMsg

type StatusMsg struct {
	Status Status
	Err    error
}

StatusMsg is emitted by RefreshCmd.

type UnstagedMsg

type UnstagedMsg struct {
	Path string
	Err  error
}

UnstagedMsg is emitted after `git reset HEAD -- <path>`.

Jump to

Keyboard shortcuts

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