#!/usr/bin/env bash # Fails if a tracked binary file over 1 MB is stored in plain git instead of LFS. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." limit=$((1024 * 1024)) status=0 while IFS= read -r -d '' path; do [[ -f "$path" ]] || continue size="$(stat -c %s "$path")" ((size > limit)) || continue # grep -I treats a file containing NUL bytes as non-matching, so text matches. if grep -Iq . "$path"; then continue fi filter="$(git check-attr filter -- "$path" | awk '{print $NF}')" if [[ "$filter" != "lfs" ]]; then echo "Binary over 1 MB is not in LFS: $path ($size bytes)" >&2 status=1 fi done < <(git ls-files -z) exit "$status"