formations/utils/hooks/pre-commit

32 lines
864 B
Bash
Executable File

#!/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