From ea2d0d93bb187f4f3b5b221f49942ca31296a9d9 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Wed, 13 Sep 2023 19:35:02 +0100 Subject: [PATCH] Change how check-file-format.sh checks changed files Prior to this patch, the `git diff` command used to identify which files to check for editorconfig compliance caught too many files, and did the expensive part of the check inside the per-file loop. By lucky chance, the editorconfig-checker container image has a `git` binary installed, so we can move the entire loop inside a single container invocation. Fixes #129. --- scripts/githooks/check-file-format.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/githooks/check-file-format.sh b/scripts/githooks/check-file-format.sh index bdd179c7..7ffa2cdc 100755 --- a/scripts/githooks/check-file-format.sh +++ b/scripts/githooks/check-file-format.sh @@ -48,18 +48,11 @@ function main() { else # Check changed files only - files=$( (git diff --diff-filter=ACMRT --name-only ${BRANCH_NAME:-origin/main}; git diff --name-only) | sort | uniq ) - if [ -n "$files" ]; then - while read file; do - docker run --rm --platform linux/amd64 \ - --volume=$PWD:/check \ - mstruebing/editorconfig-checker:$image_version \ - ec \ - --exclude '.git/' \ - "$file" - [ $? != 0 ] && exit_code=1 ||: - done < <(echo "$files") - fi + docker run --rm --platform linux/amd64 \ + --volume=$PWD:/check \ + mstruebing/editorconfig-checker:$image_version \ + sh -c 'ec --exclude ".git/" $(git diff --diff-filter=ACMRT --name-only)' + [ $? != 0 ] && exit_code=1 ||: fi }