diff

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyHunk

func ApplyHunk(base string, h Hunk) string

ApplyHunk applies a single hunk to the base file content, producing a new file with only that hunk's changes. This gives difftastic a full file for tree-sitter parsing.

func BaseContent

func BaseContent(repoRoot string, staged bool, file string) (string, error)

BaseContent retrieves the base file content for diffing. For unstaged diffs: the index version (git show :file). For staged diffs: the HEAD version (git show HEAD:file).

func RawNewFileDiff

func RawNewFileDiff(repoRoot, file string) (string, error)

RawNewFileDiff generates a unified diff for an untracked file by comparing /dev/null against the file.

func RawUnifiedDiff

func RawUnifiedDiff(repoRoot string, staged bool, file string) (string, error)

Types

type DiffOpts

type DiffOpts struct {
	Staged bool
	Base   string
	Target string
	Color  bool
	Width  int
}

type Engine

type Engine interface {
	Diff(ctx context.Context, repoRoot, file string, opts DiffOpts) (string, error)
	DiffCommit(ctx context.Context, repoRoot, base, target string, color bool, width int) (string, error)
	DiffHunks(ctx context.Context, hunks []Hunk, filename, baseContent string, color bool, width int) []string
	Name() string
}

func NewEngine

func NewEngine() Engine

type FileDiff

type FileDiff struct {
	Header string
	Path   string
	Hunks  []Hunk
}

func ParseUnifiedDiff

func ParseUnifiedDiff(raw string) []FileDiff

type Hunk

type Hunk struct {
	Header   string
	OldStart int
	OldCount int
	NewStart int
	NewCount int
	Lines    []string
}

func (Hunk) Patch

func (h Hunk) Patch(fileHeader string) string

Jump to

Keyboard shortcuts

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