Skip to content

Pass all patterns to a single git ls-files invocation - #127

Open
MattSkala wants to merge 1 commit into
mpalmer:mainfrom
MattSkala:fix-exclude-pathspecs
Open

Pass all patterns to a single git ls-files invocation#127
MattSkala wants to merge 1 commit into
mpalmer:mainfrom
MattSkala:fix-exclude-pathspecs

Conversation

@MattSkala

@MattSkala MattSkala commented Jul 23, 2026

Copy link
Copy Markdown

Fixes #126.

The Run step invoked git ls-files once 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-files call. 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. The patterns input keeps its trailing newline, and printf '%s\n' adds another; without the filter, GNU xargs would pass an empty pathspec, which git ls-files rejects as fatal.
  • xargs -r skips the command on empty input, so an empty or blank patterns value cannot run git ls-files -- on the whole repo. BSD xargs already skips empty input and accepts -r as 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).

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>
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.

GitHub Action: :(exclude) pathspecs in patterns select the entire repo

1 participant