From 231394b1cd45cd3d03622079a3bc40ab6ee72839 Mon Sep 17 00:00:00 2001 From: Benjamin Bohard Date: Tue, 8 Sep 2020 09:21:18 +0200 Subject: [PATCH] Add client-side hook --- utils/hooks/pre-commit | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 utils/hooks/pre-commit 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