Skip to content

Commit fe73a47

Browse files
author
endolinbot
committed
fix(scripts): pass shellcheck targets via git blob to avoid argv limit
Per kriskowal review on PR #401, stream the .sh file list through a git blob (`git hash-object -w --stdin` then `git cat-file blob $HASH`) instead of stuffing the list into a shell variable. This keeps us clear of ARG_MAX limits on hosts with many tracked .sh files.
1 parent cda7309 commit fe73a47

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

scripts/shellcheck.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414

1515
set -eu
1616

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)
2222

23-
if [ -z "$files" ]; then
23+
if [ -z "$(git cat-file blob "$HASH")" ]; then
2424
echo "shellcheck: no .sh files tracked; skipping."
2525
exit 0
2626
fi
2727

2828
# 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

Comments
 (0)