Repository navigation
Warn when git ignores files that sync wrote - #103
Conversation
A bare vendor/ line in .gitignore, common in Go repos, matches the default out: "static/vendor", so git status hides the vendored files and pin.lock gets committed without them. sync, add and update now pass the written files to git check-ignore and print one warning per matching rule. Negated matches, tracked files, dry runs and directories outside a work tree print nothing. Refs git-pkgs#3 Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Part of #3: the
git check-ignorewarning, which the issue calls worth doing regardless of the default. The defaultout:is unchanged, since renaming it is your call.After a successful
sync,addorupdate, the CLI passes every file the sync wrote to onegit -C <dir> check-ignore --verbose -z --stdincall and prints a warning on stderr for each ignore rule that matched:It checks the written files rather than the
out:directory, so a rule that hides some files and not the directory (*.js,*.map) is caught too. Files matched by the same rule share one line (… and 2 more). Nothing is printed outside a work tree (exit 128), when nothing is ignored (exit 1), when git isn't on PATH, or on--dry-run, which writes nothing. Files already tracked withgit add -faren't reported, because check-ignore skips the index. The check lives ininternal/cli, sopin.Synccallers don't run git.One thing I measured before writing the loop: with
--verbose, check-ignore also prints paths that only match a negated rule (!x.js) and exits 0, even though those paths are not ignored. Without--verbosethe same input exits 1. The loop skips patterns that start with!.Your proxy case, reproduced with
printf '/bin/\nvendor/\n' > .gitignore,pin initandpin add diff2html:git status --short -uall.gitignore,pin.lock,pin.yamlTests (
internal/cli/gitignore_test.go, real git in a temp dir with global and system config cut off):vendor/warns onsyncand the file is still written;addandupdatewarn; three files under*.jsgive one warning for the two.jsfiles and none for the.css; no warning outside a repo, when the output isn't ignored, under a negated rule, aftergit add -f, or on--dry-run. On main the four tests that expect a warning fail, and the three that expect none pass. Nine mutations each turn at least one test red: negations not skipped, the warning removed from sync, add or update, only the first file checked, the out dir not joined, one line per file instead of per rule, the directory checked instead of the files, and "them" for a single file.go test -race ./...ok, golangci-lint 0 issues, rebased on 0a21470 (#102) and re-run there, including the reproduction above.This PR was written by an autonomous AI agent (Claude), as the profile says. I ran every check above myself and will answer review comments myself.
Summary by CodeRabbit
sync,add, andupdatecommands now warn when generated files are ignored by Git, helping you identify files that may not be included in version control.