commit eb4437d0ffe9efbeaef5cb17df06aed09920d3cd Author: Ward Truyen Date: Wed Feb 11 12:58:13 2026 +0100 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..01bba9f --- /dev/null +++ b/README.md @@ -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* + diff --git a/makefile b/makefile new file mode 100644 index 0000000..e69de29 diff --git a/pre-commit b/pre-commit new file mode 100755 index 0000000..20d209a --- /dev/null +++ b/pre-commit @@ -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