{"modulePath":"github.com/inference-gateway/cli","version":"v0.178.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gitdiff\n\nPackage gitdiff is a small, focused data layer behind the \\`/diff\\` changes panel. It shells out to the git CLI (mirroring the exec.Command(\"git\", ...) style used elsewhere in the codebase) to list working-tree changes and to fetch the before/after content for a single changed file.\n\nIt deliberately returns raw before/after content rather than a preformatted patch: the UI renders the diff via the diffview package, which computes the line diff itself. The Source interface lives here (not in internal/domain) so it does not trigger counterfeiter mock regeneration - the only consumer is the diff viewer component, which can be tested with a hand-written fake.\n\n## Functions\n\n```go\nfunc IsRepo(workdir string) bool\n```\nIsRepo reports whether workdir is inside a git work tree.\n\n```go\nfunc RunGit(ctx context.Context, workdir string, args ...string) ([]byte, error)\n```\nRunGit runs a git command in workdir (process cwd when empty) and returns its stdout. The context bounds the command's lifetime; stderr is folded into the returned error.\n\n## Types\n\n```go\ntype FileChange struct {\n\tPath     string\n\tOrigPath string\n\tStatus   Status\n\tStaged   bool\n}\n```\nFileChange describes one changed path, in either the staged (index) group or the unstaged (working-tree) group. A path with both staged and unstaged edits (porcelain \"MM\") yields one FileChange in each group, like VS Code.\n\n```go\ntype FilePatch struct {\n\tPreamble string\n\tHunks    []Hunk\n}\n```\nFilePatch is a single file's unified diff, split into its preamble (the \"diff --git\"/\"index\"/\"---\"/\"+++\" lines) and hunks. It is the unit operated on by hunk-level (git add -p style) staging.\n\n```go\nfunc SplitFilePatchHunk(fp FilePatch, idx int) FilePatch\n```\nSplitFilePatchHunk returns a copy of fp with hunk idx replaced by the smallest independent hunks it can be broken into (see splitHunk). An out-of-range idx returns fp unchanged.\n\n```go\ntype Hunk struct {\n\tHeader string\n\tLines  []string\n}\n```\nHunk is one \"@@ ... @@\" section of a unified diff for a file.\n\n```go\ntype ReadSource interface {\n\tChanges() (staged, unstaged []FileChange, err error)\n\tDiff(fc FileChange) (oldContent, newContent string, isBinary bool, err error)\n\tWorkdir() string\n}\n```\nReadSource is the read-only subset of Source consumed by the diff viewer's PR tab: it lists changed files and returns their before/after content, but cannot stage, discard, or patch. gitSource satisfies it, and so does rangeSource.\n\n```go\nfunc NewPRSource(workdir string) ReadSource\n```\nNewPRSource returns a read-only source for the current branch's PR diff, rooted at workdir.\n\n```go\ntype Source interface {\n\t// Changes returns the staged and unstaged file groups.\n\tChanges() (staged, unstaged []FileChange, err error)\n\t// Diff returns the before/after content for a change. Refs are chosen by\n\t// group: a staged entry compares HEAD→index, an unstaged entry compares\n\t// index(→HEAD fallback)→working tree. Added/untracked → old \"\", deleted →\n\t// new \"\". isBinary is true for binary or oversized content (skip diffing).\n\tDiff(fc FileChange) (oldContent, newContent string, isBinary bool, err error)\n\t// Stage runs `git add` on the path.\n\tStage(path string) error\n\t// Unstage removes the path from the index.\n\tUnstage(path string) error\n\t// StageAll stages every working-tree change (`git add -A`): modifications,\n\t// additions, deletions, and untracked files.\n\tStageAll() error\n\t// UnstageAll removes all paths from the index (`git reset -q HEAD`), leaving\n\t// the working tree untouched.\n\tUnstageAll() error\n\t// Discard reverts a working-tree change: it restores a tracked file from the\n\t// index (HEAD when nothing is staged) and deletes an untracked file. This is\n\t// destructive - the discarded working-tree changes cannot be recovered.\n\tDiscard(fc FileChange) error\n\t// WorktreePatch returns the unstaged (index→working tree) patch for a path,\n\t// for hunk-level staging.\n\tWorktreePatch(path string) (FilePatch, error)\n\t// IndexPatch returns the staged (HEAD→index) patch for a path, for\n\t// hunk-level unstaging.\n\tIndexPatch(path string) (FilePatch, error)\n\t// ApplyHunk applies a single hunk to the index. reverse=false stages a\n\t// worktree hunk; reverse=true unstages a staged hunk.\n\tApplyHunk(fp FilePatch, hunkIndex int, reverse bool) error\n\t// ApplyLines applies only the selected change-lines of one hunk to the index.\n\t// selected holds 0-based indices into the hunk's Lines slice ('+'/'-' lines\n\t// only; others are ignored). reverse=false stages the selected worktree lines,\n\t// reverse=true unstages the selected staged lines. Unselected changes are\n\t// neutralized so they keep their prior staged/unstaged state.\n\tApplyLines(fp FilePatch, hunkIndex int, selected map[int]bool, reverse bool) error\n\t// Workdir returns the repository working directory that change paths are\n\t// relative to, for resolving an absolute path (e.g. to open in an editor).\n\tWorkdir() string\n}\n```\nSource provides the data behind the changes panel.\n\n```go\nfunc NewGitSource(workdir string) Source\n```\nNewGitSource returns a Source rooted at workdir (the repository working dir).\n\n```go\ntype Status rune\n```\nStatus is a single-letter git status code for a changed file.\n\n```go\nconst (\n\tStatusModified   Status = 'M'\n\tStatusAdded      Status = 'A'\n\tStatusDeleted    Status = 'D'\n\tStatusTypeChange Status = 'T'\n\tStatusUntracked  Status = '?'\n)\n```\n\n","path":"github.com/inference-gateway/cli/internal/services/gitdiff","name":"gitdiff","synopsis":"Package gitdiff is a small, focused data layer behind the `/diff` changes panel.","isRedistributable":true}
