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 ¶
const MaxPatchBytes = 200 << 10
MaxPatchBytes bounds each file's patch in the response.
Variables ¶
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.
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 ¶
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.