From 0602b8516badb974e7c16e0e811e5cd75fcb81ca Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Fri, 5 Apr 2024 12:55:20 +0200 Subject: [PATCH] Add 'nocommit' check to git pre-commit hook --- githooks/pre-commit | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/githooks/pre-commit b/githooks/pre-commit index cd31ad5..53ff413 100755 --- a/githooks/pre-commit +++ b/githooks/pre-commit @@ -7,6 +7,8 @@ temp=$(mktemp -p /dev/shm -d -t git-hook.XXXX) export SRC_DIR=$(pwd) export WORK_DIR=$(git rev-parse --show-toplevel) +export commit=commit + new() { git status --porcelain | grep -E '^AM|^M|^A' | sed 's/^[^ ]* *//' } @@ -22,8 +24,30 @@ check() { end" } +get_marks() { + git status --porcelain | cut --bytes 4- | while read file + do + if [ -e "$temp/index/$file" ] + then + grep -n -i no$commit "$temp/index/$file" | sed "s/:/ /" | while read line + do + echo "$file:$line" + done + fi + done +} + git checkout-index --prefix="$temp/index/" --all +marks=$(get_marks) +if [ -n "$marks" ] +then + /bin/echo -e "\x1b[31m'no$commit' mark(s) found:\x1b[0m" + echo $marks + rm -rf $temp + exit 1 +fi + cd $temp/index/ ln -s "$WORK_DIR"/.git/ .git