From ece694894bfe8758ff4984af9a0a7bc12ea817ed Mon Sep 17 00:00:00 2001 From: person93 Date: Sun, 11 May 2025 17:57:50 -0400 Subject: [PATCH] allow binary files in LFS --- pre_commit_hooks/forbid-binary | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pre_commit_hooks/forbid-binary b/pre_commit_hooks/forbid-binary index 04fe2ab..467e1a2 100755 --- a/pre_commit_hooks/forbid-binary +++ b/pre_commit_hooks/forbid-binary @@ -6,9 +6,28 @@ set -eu # pre-commit uses the "identify" pure python library to detect binary files. ################################################################################ -if [ $# -gt 0 ]; then - for filename in "${@}"; do - echo "[ERROR] ${filename} appears to be a binary file" - done - exit 1 +binaries=0 + +if command -v git-lfs >/dev/null 2>&1; then + if [ $# -gt 0 ]; then + for filename in "${@}"; do + list=$(git lfs ls-files --include "${filename}") + if [ -z "${list}" ]; then + echo "[ERROR] ${filename} appears to be a binary file" + binaries=$((binaries + 1)) + fi + done + + if [ ${binaries} -gt 0 ]; then + exit 1 + fi + fi + +else + if [ $# -gt 0 ]; then + for filename in "${@}"; do + echo "[ERROR] ${filename} appears to be a binary file" + done + exit 1 + fi fi