gitdiff

package
v0.136.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 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

Overview

Package gitdiff produces the live diff for a session's working directory by shelling out to git. It never modifies the repository.

Index

Constants

View Source
const MaxPatchBytes = 200 << 10

MaxPatchBytes bounds each file's patch in the response.

Variables

View Source
var DefaultBases = []string{"master", "main"}

DefaultBases are the branches a feature branch is measured against, in order of preference. The first that exists and is not the current branch wins; on the trunk itself none of them apply and the base stays HEAD.

View Source
var ErrNotARepo = errors.New("not a git repository")

ErrNotARepo means cwd is not inside a git work tree (→ HTTP 409).

Functions

func Head(ctx context.Context, cwd string) string

Head is the commit HEAD names in the repository holding cwd, or "" when there is none (not a repository, an unborn branch).

Types

type FileDiff

type FileDiff struct {
	Path      string `json:"path"`
	Status    string `json:"status"` // modified | added | deleted | renamed | untracked
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Patch     string `json:"patch,omitempty"`
	Binary    bool   `json:"binary,omitempty"`
}

FileDiff is one changed file.

type Result

type Result struct {
	Root   string     `json:"root"`
	Branch string     `json:"branch"`
	Files  []FileDiff `json:"files"`
	Stat   string     `json:"stat"`
	// Base names what the changes are measured against, so a reader is never
	// left guessing whether a figure covers the branch or only the working
	// tree. Empty means HEAD (the trunk, or a repo with no other branch).
	Base string `json:"base,omitempty"`
	// BaseBranch is the trunk this branch forked from, when one was found.
	BaseBranch string `json:"base_branch,omitempty"`
}

Result is the diff of a working tree.

func Diff

func Diff(ctx context.Context, cwd string) (*Result, error)

Diff returns what this session's branch changed: its own commits since it left the trunk, plus everything still uncommitted, plus untracked files.

It used to diff the working tree against HEAD alone, which answers "what have I not committed yet" — a different question, and the wrong one for a panel titled with the branch name. On a branch whose work was committed, every file it changed had already moved into HEAD, so the panel reported no changes at all while the session had rewritten twenty files. Measuring from the merge base makes the branch the unit, which is what the reader is looking at.

type Totals added in v0.102.0

type Totals struct {
	Files     int `json:"files"`
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	// Binary counts the changed files with no line counts.
	Binary int `json:"binary,omitempty"`
}

Totals is how much a working tree changed since a commit: files and lines, committed or not, untracked files included.

func Since added in v0.102.0

func Since(ctx context.Context, cwd, base string) (Totals, error)

Since totals what the working tree at cwd changed since base — a commit, a branch, anything git resolves — counting commits made since, uncommitted edits and untracked files that git does not ignore. It never modifies the repository. With base empty it is measured as Diff measures (the trunk's fork point, else HEAD).

Jump to

Keyboard shortcuts

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