From 524f99dcc8097a4bc047c7886e796188b7d57973 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 18 Oct 2017 12:14:37 +0200
Subject: [PATCH] Added git pre-commit hook in .hooks-subdirectory.

Hook checks for correctly committing files tracked by git lfs.
---
 .hooks/pre-commit | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 .hooks/pre-commit

diff --git a/.hooks/pre-commit b/.hooks/pre-commit
new file mode 100644
index 00000000000..2f1711eea5f
--- /dev/null
+++ b/.hooks/pre-commit
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+# Activate via the following setting in .git/config
+# [core]
+#    hooksPath = .hooks
+#
+# **Or** by copying this file to .git/hooks/pre-commit
+
+echo "Running pre-commit hook.."
+
+set -e
+
+RETURN_CODE=0
+
+### git-lfs check ###
+BINARY_FILES=""
+CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
+LFS_FILES=$(echo $CHANGED_FILES | xargs git check-attr filter | grep 'filter: lfs$' | sed -e 's/: filter: lfs//')
+
+for FILE in $LFS_FILES; do
+    SOFT_SHA=$(git hash-object -w $FILE)
+    RAW_SHA=$(git hash-object -w --no-filters $FILE)
+
+    if [ $SOFT_SHA == $RAW_SHA ]; then
+        BINARY_FILES="$FILE\n$BINARY_FILES"
+    fi
+done
+
+if [[ -n "$BINARY_FILES" ]]; then
+    echo "Attention!"
+    echo "----------"
+    echo "You tried to commit files tracked by git-lfs as standard git objects:"
+    echo -e "\x1B[31m$BINARY_FILES\x1B[0m"
+    echo "Revert your changes and commit those files with git-lfs!"
+    echo "See https://docs.opengeosys.org/docs/devguide/getting-started/prerequisites"
+    echo "----------"
+    RETURN_CODE=1
+fi
+
+exit $RETURN_CODE
-- 
GitLab