gitdiff

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitdiff shells out to system git to compute which lines in which files a change touches. The result feeds diff-scoping in the engine — a gate finding on an untouched line is pre-existing noise, not a new bug.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAGitRepo = errors.New("gauntlet: not a git repository")

ErrNotAGitRepo is returned when the target dir isn't a git worktree.

Functions

func Compute

func Compute(ctx context.Context, root string, mode Mode, ref string) (map[string]FileChanges, error)

Compute runs the diff and parses it into per-file line ranges. `ref` is only used for ModeSince.

func Parse

func Parse(diff []byte) (map[string]FileChanges, error)

Parse turns unified-diff bytes into per-file line ranges. Emits only the new-side ranges; deletes contribute nothing (no lines to scope to).

Types

type EmptyScope

type EmptyScope struct{}

EmptyScope: no diff was computed (whole-tree mode). Everything is in-scope.

func (EmptyScope) Files

func (EmptyScope) Files() []string

func (EmptyScope) Includes

func (EmptyScope) Includes(string, int) bool

func (EmptyScope) IsScoped

func (EmptyScope) IsScoped() bool

type FileChanges

type FileChanges struct {
	Path     string
	IsNew    bool // added file — all findings on it count as new
	IsBinary bool
	Ranges   []LineRange
}

FileChanges is what a diff produced for one file: touched line ranges on the new side, plus a flag for "this file is entirely new" (any line counts).

type LineRange

type LineRange struct {
	Start int // first changed line, 1-indexed
	End   int // last changed line, inclusive
}

LineRange is a half-open range on the new (+) side of a diff hunk. Start is 1-indexed. A rename-only file has zero ranges.

func (LineRange) Contains

func (r LineRange) Contains(l int) bool

Contains reports whether line L falls in this range.

type Mode

type Mode int

Mode picks the diff scope.

const (
	// ModeStaged: `git diff --cached --unified=0` (pre-commit).
	ModeStaged Mode = iota
	// ModeSince: `git diff --unified=0 <ref>...HEAD` (branch vs base ref).
	ModeSince
	// ModeWholeTree: no scoping — every finding is "new".
	ModeWholeTree
)

type Scope

type Scope interface {
	Includes(file string, line int) bool
	IsScoped() bool // false for whole-tree; findings are never suppressed
	Files() []string
}

Scope is the read-only interface the engine uses to ask "is this finding on a changed line?" ModeWholeTree returns an EmptyScope where every line is considered new.

func FromChanges

func FromChanges(c map[string]FileChanges) Scope

FromChanges builds a Scope from a Compute result. Passing nil (whole-tree) returns EmptyScope.

Jump to

Keyboard shortcuts

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