check_for_blobs.sh: respect gitignore (#876)

This commit is contained in:
Mrmaxmeier 2022-11-05 23:30:26 +01:00 committed by GitHub
parent b9bd0dd6b7
commit 8e6eaf7002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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