From 8e6eaf70022672bd574f687e7fc4b45160f324d3 Mon Sep 17 00:00:00 2001 From: Mrmaxmeier <3913977+Mrmaxmeier@users.noreply.github.com> Date: Sat, 5 Nov 2022 23:30:26 +0100 Subject: [PATCH] check_for_blobs.sh: respect gitignore (#876) --- scripts/check_for_blobs.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/check_for_blobs.sh b/scripts/check_for_blobs.sh index cf79db0490..03f844b1f7 100755 --- a/scripts/check_for_blobs.sh +++ b/scripts/check_for_blobs.sh @@ -1,19 +1,30 @@ #!/bin/bash -blobs=$(find . -type f -exec sh -c ' - for f; do - mimetype -b "$f" | grep -Eq "application/(x-object|x-executable)" && - printf "%s\n" "$f" - done -' sh {} +) +declare -a blobs -if [ -z "$blobs" ] +KNOWN_GOOD_FILE_EXTENSIONS=("rs" "c" "h" "cc" "sh" "py" "toml" "yml" "json" "md" "gitignore" "png") + +while read -r file; do + # NOTE: mimetype detection spawns a perl process for each file and is pretty slow. + # we work around this by skipping files with known-good extensions. + ext="${file##*.}" + for skipExt in "${KNOWN_GOOD_FILE_EXTENSIONS[@]}"; do + if [ "$ext" = "$skipExt" ]; then + continue 2 + fi + done + if mimetype -b "$file" | grep -Eq "application/(x-object|x-executable)"; then + blobs+=("$file"); + fi +done < <(git ls-files --exclude-standard --cached --others) + +if [ ${#blobs[@]} -eq 0 ] then echo "No object or executable files in the root directory" exit 0 else echo "Hey! There are some object or executable file in the root directory!" - echo "$blobs" + echo "${blobs[@]}" echo "Aborting." exit 1 fi