@@ -56,48 +56,34 @@ function main-invocation() {
5656 is-arg-true " ${dry_run:- false} " && dry_run_opt=" --dry-run"
5757
5858 check=${check:- working-tree-changes}
59- case $check in
60- " all" )
61- filter=" git ls-files"
62- ;;
63- " staged-changes" )
64- filter=" git diff --diff-filter=ACMRT --name-only --cached"
65- ;;
66- " working-tree-changes" )
67- filter=" git diff --diff-filter=ACMRT --name-only"
68- ;;
69- " branch" )
70- filter=" git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:- origin/ main} "
71- ;;
72- * )
73- echo " Unrecognised check mode: $check " >&2 && exit 1
74- ;;
75- esac
59+ if ! declare -f " list-files-to-check--$check " > /dev/null 2>&1 ; then
60+ echo " Unrecognised check mode: $check " >&2 && exit 1
61+ fi
7662
7763 if command -v editorconfig > /dev/null 2>&1 && ! is-arg-true " ${FORCE_USE_DOCKER:- false} " ; then
7864 method=--natively
7965 else
8066 method=--via-docker
8167 fi
8268
83- filter= " $filter " dry_run_opt=" ${dry_run_opt:- } " scripts/githooks/check-file-format.sh " $method "
69+ dry_run_opt=" ${dry_run_opt:- } " scripts/githooks/check-file-format.sh " $method " $( list-files-to-check-- " $check " )
8470}
8571
8672# Run editorconfig natively.
8773# Arguments (provided as environment variables):
8874# dry_run_opt=[dry run option]
89- # filter=[git command to filter the files to check]
75+ # Arguments (provided as positional parameters): files to check
9076function main-tool-wrapper--natively() {
9177
9278 # shellcheck disable=SC2046,SC2086
9379 editorconfig \
94- --exclude ' .git/' $dry_run_opt $( $filter )
80+ --exclude ' .git/' $dry_run_opt " $@ "
9581}
9682
9783# Run editorconfig in a Docker container.
9884# Arguments (provided as environment variables):
9985# dry_run_opt=[dry run option]
100- # filter=[git command to filter the files to check]
86+ # Arguments (provided as positional parameters): files to check
10187function main-tool-wrapper--via-docker() {
10288
10389 # shellcheck disable=SC1091
@@ -111,7 +97,25 @@ function main-tool-wrapper--via-docker() {
11197 docker run --rm --platform linux/amd64 \
11298 --volume " $PWD " :/check \
11399 " $image " \
114- sh -c " ec --exclude '.git/' $dry_run_opt \$ ($filter ) /dev/null"
100+ sh -c " ec --exclude '.git/' $dry_run_opt $( printf ' %q ' " $@ " ) /dev/null"
101+ }
102+
103+ # ==============================================================================
104+
105+ function list-files-to-check--all() {
106+ git ls-files
107+ }
108+
109+ function list-files-to-check--staged-changes() {
110+ git diff --diff-filter=ACMRT --name-only --cached
111+ }
112+
113+ function list-files-to-check--working-tree-changes() {
114+ git diff --diff-filter=ACMRT --name-only
115+ }
116+
117+ function list-files-to-check--branch() {
118+ git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:- origin/ main}
115119}
116120
117121# ==============================================================================
0 commit comments