@@ -50,16 +50,16 @@ function main() {
5050 check=${check:- working-tree-changes}
5151 case $check in
5252 " all" )
53- filter=" git ls-files"
53+ filter=" git ls-files -z "
5454 ;;
5555 " staged-changes" )
56- filter=" git diff --diff-filter=ACMRT --name-only --cached"
56+ filter=" git diff --diff-filter=ACMRT --name-only --cached -z "
5757 ;;
5858 " working-tree-changes" )
59- filter=" git diff --diff-filter=ACMRT --name-only"
59+ filter=" git diff --diff-filter=ACMRT --name-only -z "
6060 ;;
6161 " branch" )
62- filter=" git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:- origin/ main} "
62+ filter=" git diff --diff-filter=ACMRT --name-only -z ${BRANCH_NAME:- origin/ main} "
6363 ;;
6464 * )
6565 echo " Unrecognised check mode: $check " >&2 && exit 1
@@ -79,9 +79,17 @@ function main() {
7979# filter=[git command to filter the files to check]
8080function run-editorconfig-natively() {
8181
82- # shellcheck disable=SC2046,SC2086
82+ local files=()
83+ while IFS= read -r -d ' ' file; do
84+ files+=(" $file " )
85+ done < <( $filter )
86+
87+ # If no files found, exit successfully
88+ [[ ${# files[@]} -eq 0 ]] && return 0
89+
90+ # shellcheck disable=SC2086
8391 editorconfig \
84- --exclude ' .git/' $dry_run_opt $( $filter )
92+ --exclude ' .git/' $dry_run_opt " ${files[@]} "
8593}
8694
8795# Run editorconfig in a Docker container.
@@ -95,13 +103,24 @@ function run-editorconfig-in-docker() {
95103
96104 # shellcheck disable=SC2155
97105 local image=$( name=mstruebing/editorconfig-checker docker-get-image-version-and-pull)
106+
107+ local files=()
108+ while IFS= read -r -d ' ' file; do
109+ files+=(" $file " )
110+ done < <( $filter )
111+
98112 # We use /dev/null here as a backstop in case there are no files in the state
99113 # we choose. If the filter comes back empty, adding `/dev/null` onto it has
100114 # the effect of preventing `ec` from treating "no files" as "all the files".
115+ if [[ ${# files[@]} -eq 0 ]]; then
116+ files=(/dev/null)
117+ fi
118+
119+ # shellcheck disable=SC2086
101120 docker run --rm --platform linux/amd64 \
102121 --volume " $PWD " :/check \
103122 " $image " \
104- sh -c " ec --exclude '.git/' $dry_run_opt \$ ( $filter ) /dev/null "
123+ ec --exclude ' .git/' $dry_run_opt " ${files[@]} "
105124}
106125
107126# ==============================================================================
0 commit comments