diff --git a/utils/hooks/pre-commit b/utils/hooks/pre-commit new file mode 100755 index 0000000..05481da --- /dev/null +++ b/utils/hooks/pre-commit @@ -0,0 +1,31 @@ +#!/bin/sh + +checkout_branch="$(git branch --show-current)" +presentations_indexed_files="$(git diff --cached --name-only -- presentations/ | wc -l)" +indexed_files="$(git diff --cached --name-only | wc -l)" + +case "$checkout_branch" in + master) + if [ "${presentations_indexed_files}" -gt 0 ] + then + cat <<\EOF +Error: Attempt to add files in presentations folder in master branch. +Files in presentations folder are to be added in special branches xelatex/*. +EOF + exit 1 + fi + ;; + xelatex/*) + if [ $presentations_indexed_files -ne $indexed_files ] + then + cat <<\EOF +Error: Attempt to add files outside presentations folder in special branch xelatex/*. +This branch follows only files in presentations folder. +EOF + exit 1 + fi + ;; + *) exit 0;; +esac + +exit 0