Skip to content

Warn when git ignores files that sync wrote - #103

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
charlie-morrison:warn-gitignored-out
Nov 29, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
charlie-morrison:warn-gitignored-out

Conversation

@charlie-morrison

@charlie-morrison charlie-morrison commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3: the git check-ignore warning, which the issue calls worth doing regardless of the default. The default out: is unchanged, since renaming it is your call.

After a successful sync, add or update, the CLI passes every file the sync wrote to one git -C <dir> check-ignore --verbose -z --stdin call and prints a warning on stderr for each ignore rule that matched:

warning: git ignores static/vendor/diff2html/diff2html.js (.gitignore:2 "vendor/"), which pin.lock lists; commit it with git add -f or change out: in the manifest

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 with git add -f aren't reported, because check-ignore skips the index. The check lives in internal/cli, so pin.Sync callers 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 --verbose the same input exits 1. The loop skips patterns that start with !.

Your proxy case, reproduced with printf '/bin/\nvendor/\n' > .gitignore, pin init and pin add diff2html:

main (0a21470) this branch
stderr nothing the warning above
git status --short -uall .gitignore, pin.lock, pin.yaml the same, since the warning doesn't change what's written

Tests (internal/cli/gitignore_test.go, real git in a temp dir with global and system config cut off): vendor/ warns on sync and the file is still written; add and update warn; three files under *.js give one warning for the two .js files and none for the .css; no warning outside a repo, when the output isn't ignored, under a negated rule, after git 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

  • New Features
    • The sync, add, and update commands now warn when generated files are ignored by Git, helping you identify files that may not be included in version control.
    • Warnings group files affected by the same ignore rule. Output files are still written as usual.

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>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

After successful add, sync, and update operations, the CLI checks written output files against Git ignore rules. It reports matching rules to stderr and leaves the write operation intact.

Changes: Ignored output warnings

Layer / File(s) Summary
Check written paths against Git ignore rules
internal/cli/gitignore.go
The shared helper checks files written by a sync, skips missing sync data and Git command errors, excludes negated rules, and groups warnings by ignore source, line, and pattern.
Wire successful commands and test warning behavior
internal/cli/add.go, internal/cli/sync.go, internal/cli/update.go, internal/cli/gitignore_test.go
The commands call the helper after successful writes. Tests cover warning output, grouping, skipped cases, and confirmation that warnings do not prevent output from being written.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant warnGitIgnored
  participant Git
  CLI->>warnGitIgnored: pass directory and sync result after successful write
  warnGitIgnored->>Git: check written paths with git check-ignore
  Git-->>warnGitIgnored: return matching ignore rules
  warnGitIgnored-->>CLI: write grouped warnings to stderr
Loading

Possibly related issues

Suggested reviewers: andrew

Merge Risk: Minimal · up to 10611

This change adds a stderr warning after sync, add, or update when Git would ignore files that were written. It does not change what is written. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Warn when git ignores files that sync wrote" matches the main change: after a successful sync, add, or update, the CLI runs git check-ignore on the written files and warns when Git ignores …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Warn when git ignores files that sync wrote" matches the main change: after a successful sync, add, or update, the CLI runs git check-ignore on the written files and warns when Git ignores them. It is specific, concise, and matches the PR objectives and the warnGitIgnored changes in internal/cli.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 968cd72f-1f7f-4628-b277-6b7379b7fa28
Commits

Reviewing files that changed from the base of the PR and between 0a21470 and 10611eb.

Files selected for processing: 5

  • internal/cli/add.go
  • internal/cli/gitignore.go
  • internal/cli/gitignore_test.go
  • internal/cli/sync.go
  • internal/cli/update.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@andrew
andrew merged commit 7709a4e into git-pkgs:main Nov 29, 2026
6 checks passed
@charlie-morrison
charlie-morrison deleted the warn-gitignored-out branch November 30, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants