Repository navigation
secret-guard: a commit scans only the untracked files its git add names - #178
Conversation
`git add a.ts && git commit` read every untracked file git doesn't ignore. One big untracked file the commit leaves out (a 2.3 MB build report) made every such commit ask "too big to check whole". Now the untracked scan takes the add's pathspecs; `git add .`, `-A`, `-u`, globs and `$vars` still read every untracked file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hamzafer
left a comment
There was a problem hiding this comment.
Thanks @padschneider, skipping big build files on a narrow git add is a nice win. The catch is that once the scan only covers the paths we parse, any path we parse wrong is a file that gets committed unscanned. A few cases that slip through today:
- Escaped spaces:
git add config\ prod.env && git commitsplits intoconfig\andprod.env, so the real file is never scanned. --pathspec-from-file/--pathspec-file-nul:git add a.ts --pathspec-from-file=l.txtreturns["a.ts"], and the files inl.txtare skipped (the space form also treatsl.txtas a path).- The add's own
-C:git -C sub add x.env && git commityieldsx.env, butls-filesruns in the commit's cwd, sosub/x.envis missed. - Brace expansion,
~, line continuation:git add .env{,.local},git add ~/x, and a\line break before the next path all drop files. - One bad pathspec empties the scan: if any path is outside the repo or in a submodule,
ls-filesexits 128 anduntracked()returns'', so no untracked file is scanned at all.
Suggested shape: make addPaths fail closed. Narrow only when every word after add is a plain relative path (no \ { } ~ : or $, no options outside a small known-safe set, no -C on the add, no non-leading cd), and fall back to the full untracked scan whenever ls-files exits non-zero. Tests for the cases above would lock it in.
Small docs note: docs/mods.md and the site page still say a commit scans the new files whenever the command runs git add, so they'll need a tweak to match.
…is plain Review follow-up. addPaths now fails closed: it narrows only when each word after `add` is a plain relative path or a known-safe option (-v, -f, -N), the add has no global options of its own, nothing comes before `git` in its step, and no cd moves the shell after the start. Escaped spaces, braces, ~, line continuations, pathspec magic, --pathspec-from-file, redirections, -C on the add and a commit's own -C all scan every untracked file, as before. A pathspec git refuses (ls-files exits non-zero) falls back to the full list instead of none. Tests cover each case; docs and site page say what's narrowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the careful review. All points are addressed in 94462aa:
|
…s plain git
addPaths now narrows only when the command is an optional leading cd plus
git add, commit, push and status. A hidden add beside a plain one (git stage,
bash -c, eval, a heredoc, "git" add, git -c alias), a cd the parse missed
({ cd x; }, command cd) and a path glued from quoted and bare parts all scan
every untracked file again. A quoted-heredoc commit message still narrows.
…ne; cd - scans everything
hamzafer
left a comment
There was a problem hiding this comment.
Thanks @padschneider, nice work on the fail-closed parse. I pushed one follow-up commit (07e13c0) on top: addPaths now narrows only when the whole command is a leading cd plus plain git add/commit/push/status steps, so a hidden add next to a plain one (git stage, bash -c, eval, "git" add), a missed cd ({ cd x; }, command cd, cd -), a path glued from quoted and bare parts, and a commit-message heredoc with an early EOF line all scan every untracked file again. A quoted-heredoc commit message still narrows. Tests cover each case.
What happened
In a repo with one big untracked file lying around (here a 2.3 MB esbuild meta report), every
git add <files> && git commitasked:untracked()lists every untracked file git doesn't ignore, whatever thegit addnamed, and any file over 1 MB marks the scan as cut. So the ask came up on every commit, even though the commit never included that file.Change
addPaths(command)reads the pathspecs of eachgit addin the command.untracked()passes them togit ls-files --others -- <paths>, so only files the add stages are read..,-A/--all,-u, globs,$vars.Tests
git add .still asks, andaddPathscases are covered. The mockls-filesnow honours pathspecs.claude plugin testor the repo tests on my machine. Please let CI check.🤖 Generated with Claude Code