gitdiff

package
v2.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLineChanged

func IsLineChanged(cl ChangedLines, absFile string, line int) bool

IsLineChanged reports whether absFile at the given line falls within any changed range in cl.

When line == 0 (position could not be determined), the function returns true to avoid filtering mutations at unknown positions.

When a file is present in cl but line falls outside every changed range, false is returned — the mutation targets an unchanged line. When a file is absent from cl entirely, all of its mutations are filtered.

Types

type ChangedLines

type ChangedLines map[string][]LineRange

ChangedLines maps relative file paths (from repo root, forward-slash separated) to the line ranges that were added or modified in the diff. A nil ChangedLines means "no filter" — all mutations are run.

func ParseChangedLines

func ParseChangedLines(base string) (ChangedLines, error)

ParseChangedLines diffs the working tree against the merge-base of <base> and HEAD, and returns each modified file's changed line ranges. Deleted-only hunks (count == 0) are excluded — there is nothing to mutate on a removed line.

Diffing against the merge-base (rather than the tip of <base>) reports only the changes introduced on the current branch — exactly what a pull request shows — while still including uncommitted working-tree changes. A plain two-dot `git diff <base>` would also report commits that landed on <base> after the branch point, wrongly attributing those unrelated changes to the feature branch when it is behind its target.

If no merge-base can be found (e.g. unrelated histories), it falls back to diffing against <base> directly.

type LineRange

type LineRange struct{ Start, End int }

LineRange is an inclusive [Start, End] range of line numbers.

Jump to

Keyboard shortcuts

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