|
14 | 14 |
|
15 | 15 | set -eu |
16 | 16 |
|
17 | | -# Read NUL-delimited paths into a single newline-separated list so the body |
18 | | -# can branch on emptiness. xargs is not used directly because BSD xargs |
19 | | -# (macOS) lacks `-r` and runs the command on an empty list, which would |
20 | | -# invoke `shellcheck` with no positional arguments and read from stdin. |
21 | | -files=$(git ls-files -z '*.sh' | tr '\0' '\n') |
| 17 | +# Stash the file list as a git blob and stream it back out, rather than |
| 18 | +# holding it in a shell variable. This keeps us clear of ARG_MAX limits |
| 19 | +# on hosts with a large number of tracked .sh files, and lets the body |
| 20 | +# branch on emptiness without an oversize positional-argument list. |
| 21 | +HASH=$(git ls-files -z '*.sh' | tr '\0' '\n' | git hash-object -w --stdin) |
22 | 22 |
|
23 | | -if [ -z "$files" ]; then |
| 23 | +if [ -z "$(git cat-file blob "$HASH")" ]; then |
24 | 24 | echo "shellcheck: no .sh files tracked; skipping." |
25 | 25 | exit 0 |
26 | 26 | fi |
27 | 27 |
|
28 | 28 | # shellcheck disable=SC2086 |
29 | | -# Word splitting on $files is intentional: each line is a separate path |
30 | | -# and tracked .sh filenames in this repo do not contain whitespace. |
31 | | -# `git ls-files` would happily emit NULs for whitespace-bearing names; if |
32 | | -# such a name lands here, switch to xargs -0 with a portability shim. |
33 | | -echo "$files" | xargs shellcheck -S warning "$@" |
| 29 | +# Word splitting on the blob's contents is intentional: each line is a |
| 30 | +# separate path and tracked .sh filenames in this repo do not contain |
| 31 | +# whitespace. `git ls-files` would happily emit NULs for whitespace-bearing |
| 32 | +# names; if such a name lands here, switch to xargs -0 with a portability |
| 33 | +# shim. |
| 34 | +git cat-file blob "$HASH" | xargs shellcheck -S warning "$@" |
0 commit comments