Skip to content

Commit

Permalink
Change how check-file-format.sh checks changed files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
regularfry authored Sep 13, 2023
1 parent fac3252 commit a264a43
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions scripts/githooks/check-file-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a264a43

Please sign in to comment.