Pass all patterns to a single git ls-files invocation - #127
Open
MattSkala wants to merge 1 commit into
Open
Conversation
Running git ls-files once per pattern line and unioning the results breaks :(exclude) pathspecs: a lone exclude pathspec matches everything else in the repo, so the union swallows the positive patterns and the validator runs on every tracked file. Passing all patterns to one git ls-files call keeps the existing union of positive pathspecs and lets exclude pathspecs subtract from them, as git documents. Blank lines are dropped so the trailing newline on the patterns input cannot become an empty pathspec, and xargs -r (a no-op on BSD xargs) avoids running git ls-files on the whole repo when the input is empty. Fixes mpalmer#126 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126.
The
Runstep invokedgit ls-filesonce per pattern line and unioned the results. An:(exclude)pathspec therefore ran as a standalone invocation, where it matches everything else in the repo, and the union swallowed the positive patterns — the validator then ran on every tracked file.This change passes all patterns to one
git ls-filescall. Positive pathspecs still union, so the default patterns select the same files as before, and exclude pathspecs now subtract from the positive ones as git documents.Two guards keep the single invocation safe:
grep -v '^[[:space:]]*$'drops blank lines. Thepatternsinput keeps its trailing newline, andprintf '%s\n'adds another; without the filter, GNU xargs would pass an empty pathspec, whichgit ls-filesrejects as fatal.xargs -rskips the command on empty input, so an empty or blankpatternsvalue cannot rungit ls-files --on the whole repo. BSD xargs already skips empty input and accepts-ras a no-op, so this works on both Linux and macOS runners.Verified locally on the default patterns (identical file list before and after) and on the reproduction from #126 (exclude now subtracts instead of selecting the repo).