gitdiff

package
v0.58.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 8 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

This section is empty.

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.

Jump to

Keyboard shortcuts

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