Add client-side hook

This commit is contained in:
Benjamin Bohard 2020-09-08 09:21:18 +02:00
parent 70ad496b06
commit 231394b1cd
1 changed files with 31 additions and 0 deletions

31
utils/hooks/pre-commit Executable file
View File

@ -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