diff --git a/build/git-pre-receive-hook b/build/git-pre-receive-hook new file mode 100755 index 0000000..8b58ad9 --- /dev/null +++ b/build/git-pre-receive-hook @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +block_push=0 + +while read -r old new refname; do + while read -r added deleted filename; do + if [[ "$added" == "-" && "$deleted" == "-" ]]; then + block_push=1 + echo "ERROR: ${filename} is a binary file." + fi + done < <(git diff --numstat "${old}..${new}") + + if [[ $block_push -eq 1 ]]; then + echo "The ref '${refname}' has been rejected" + fi +done + +if [[ $block_push -eq 1 ]]; then + echo "Binary files blocked. Please use git-lfs to push to this repo." + exit 1 +fi