{"modulePath":"github.com/Fendix-app/Fendix/go","version":"v0.0.0-20261028135234-a02776cc5df9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gitdiff\n\nPackage gitdiff resolves the set of files changed in a working tree and exposes a path Allowlist that the whitebox scanners consult to scope a scan to only those files — the engine half of \"diff-aware scanning\" (\\`fendix scan --diff\\[=ref] --staged\\`), the single most important developer-workflow feature in the 90-day cut.\n\nWhy os/exec git instead of go-git: the codebase deliberately avoids the go-git dependency (it is large and has surprising defaults — see internal/pluginscmd). Resolving a changed-file list is a one-shot \\`git diff --name-only\\` shell-out; the heavyweight library buys us nothing here. The only git feature we need is name-only diff output, which every git since 1.x prints identically.\n\nThe Allowlist is intentionally a separate, scanner-agnostic type so the secrets / textscan / semgrep packages can filter against it without importing each other or the orchestrator. A nil \\*Allowlist means \"no diff scoping\" and every scanner behaves exactly as it does in a full scan — diff mode can only ever \\*narrow\\* the file set, never change detection logic, so it cannot move the heavy-eval F1 score.\n\n## Functions\n\n```go\nfunc ChangedFiles(ctx context.Context, opts Options) ([]string, error)\n```\nChangedFiles returns the repo-relative paths of files changed under the given options, in sorted order, with deletions excluded (a deleted file has nothing left to scan). The returned slice is empty (not nil) when the tree is clean, so callers can distinguish \"nothing changed\" from an error.\n\nRenames are reported as their new path (--diff-filter excludes the old side via D). Paths git would quote (those containing unusual bytes) are returned verbatim from \\`-z\\` NUL-delimited output, so no shell unquoting is needed.\n\n```go\nfunc TraversesSymlink(root, abs string) bool\n```\nTraversesSymlink reports whether reaching abs from root crosses a symlinked directory component (or escapes root). filepath.WalkDir never descends into symlinked directories, so the diff-aware fast scanners MUST skip any allowlist entry whose parent path traverses one — otherwise they read files the full walk would never reach, breaking walk parity and (worse) letting a symlinked parent point outside the repo. A bare os.Lstat(abs) does not catch this: it follows intermediate symlinks and only reveals a final-component symlink. We Lstat each directory component instead. Returns true (refuse) on any error or if abs is not contained in root. root may be relative; it is resolved first, like abs.\n\n## Types\n\n```go\ntype Allowlist struct {\n\t// contains filtered or unexported fields\n}\n```\nAllowlist is a set of absolute file paths a diff-aware scan is restricted to. A nil \\*Allowlist means \"no scoping\" — see the package doc. Methods are nil-safe so callers can hold a \\*Allowlist field that is nil in full-scan mode and pass it straight to scanners.\n\n```go\nfunc NewAllowlist(root string, paths []string) *Allowlist\n```\nNewAllowlist builds an Allowlist from repo-relative paths resolved against root. Paths are cleaned and made absolute so a scanner walking an absolute tree (secrets/textscan call filepath.Abs on their root) can match entries directly. An empty paths slice yields a non-nil, empty Allowlist that matches nothing — the correct behaviour for \"diff requested, zero files changed\" (scan nothing, not everything).\n\n```go\nfunc (a *Allowlist) AbsPaths() []string\n```\nAbsPaths returns the allowlist entries as cleaned absolute paths, sorted. The diff-aware scanners use it to scan only the changed files directly — O(changed files) — instead of walking the whole tree to filter down to them. A nil/empty allowlist yields nil.\n\n```go\nfunc (a *Allowlist) Allows(path string) bool\n```\nAllows reports whether the given path is in the allowlist. A nil Allowlist allows everything (full-scan semantics). The path is cleaned and absolutised before lookup so callers may pass either absolute or root-relative paths.\n\n```go\nfunc (a *Allowlist) CheckScope(root string) error\n```\nCheckScope reports whether the allowlist can safely scope a scan of root: root resolves, and every entry lies under it and exists. ChangedFiles drops deletions, so an entry that does not exist means git's repository-relative path did not map onto the tree under root, as happens when root is a subdirectory of the repository. A non-nil error means the diff scope cannot be trusted, and the caller must widen to a full scan rather than narrow to files no scanner can find. A nil or empty allowlist is always in scope.\n\n```go\nfunc (a *Allowlist) ContainsBase(names ...string) bool\n```\nContainsBase reports whether any allowlisted file has the given base name (e.g. \"go.mod\", \"package-lock.json\", \"poetry.lock\"). The SCA gate uses this to decide whether a dependency manifest changed and the ecosystem's dep-CVE scan must run. Matching is on the final path element only, so a nested service's manifest (services/api/requirements.txt) still triggers.\n\n```go\nfunc (a *Allowlist) Empty() bool\n```\nEmpty reports whether the allowlist scopes the scan to zero files. Always false for a nil Allowlist (full scan). Lets the orchestrator short-circuit the expensive whitebox walk when a diff matched nothing scannable.\n\n```go\nfunc (a *Allowlist) Len() int\n```\nLen returns the number of files in the allowlist (0 for nil).\n\n```go\nfunc (a *Allowlist) RelPaths(root string) ([]string, error)\n```\nRelPaths returns the allowlist entries relative to root, sorted, as the semgrep \\`--include\\` set. root may be relative; it is resolved first. An entry that is not under root is an error: it has no root-relative form, and handing a scanner its absolute path as a filter would match nothing while the run still looked clean. A nil or empty allowlist yields no paths.\n\n```go\ntype Options struct {\n\t// RepoRoot is the directory the git command runs in. Empty means the\n\t// process working directory. The resolved Allowlist paths are made\n\t// absolute against this root.\n\tRepoRoot string\n\t// Ref, when non-empty, diffs the working tree (or the index, if\n\t// Staged) against this git ref — a branch, tag, or commit-ish such as\n\t// \"origin/main\" or \"HEAD~1\". Empty Ref diffs against HEAD.\n\tRef string\n\t// Staged restricts the diff to changes staged in the index\n\t// (`git diff --cached`) — the set a pre-commit hook must scan. When\n\t// false, unstaged working-tree changes are included too.\n\tStaged bool\n}\n```\nOptions selects which changed-file set git should report.\n\n","path":"github.com/Fendix-app/Fendix/go/internal/gitdiff","name":"gitdiff","synopsis":"Package gitdiff resolves the set of files changed in a working tree and exposes a path Allowlist that the whitebox scanners consult to scope a scan to only those files — the engine half of \"diff-aware scanning\" (`fendix scan --diff[=ref] --staged`), the single most important developer-workflow feature in the 90-day cut.","isRedistributable":true}
