Initial commit

This commit is contained in:
2026-02-11 12:58:13 +01:00
commit eb4437d0ff
3 changed files with 48 additions and 0 deletions

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# Git config
The file ``pre-commit`` is to be placed in the folder ``.git/hooks/``
It wil prevent making a commit on the branches *master*, *main* and *production*

0
makefile Normal file
View File

43
pre-commit Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$branch" == "main" || "$branch" == "master" || "$branch" == "production" ]]; then
# Check if the output is associated with a terminal (TTY)
if [ -t 1 ]; then
# TERMINAL MODE: Ask for confirmation
echo ""
echo "****************************************************"
echo "WARNING: You are currently on the [$branch] branch."
echo "****************************************************"
exec < /dev/tty
read -p "Do you really want to commit to this branch? (y/N): " confirm
exec < /dev/null
if [[ "${confirm,,}" != "y" ]]; then
echo ""
echo "Commit aborted."
echo "TIP: To bypass this check in an emergency, use:"
echo " git commit --no-verify -m \"your message\""
echo ""
exit 1
fi
else
# GUI MODE: Block and explain (since we can't prompt the user)
echo ""
echo "****************************************************"
echo "BLOCKER: Commit to [$branch] rejected via GUI."
echo "****************************************************"
echo "Direct commits to this branch are restricted."
echo ""
echo "TO PROCEED:"
echo "1. Use a terminal to confirm the commit manually."
echo "2. Or use the --no-verify flag in your terminal."
echo ""
exit 1
fi
fi
exit 0