diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100644 index 0000000..a336722 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,18 @@ +#!/bin/bash + +COMMIT_MESSAGE_FILE_PATH=$1 +MESSAGE=$(cat "$COMMIT_MESSAGE_FILE_PATH") + +if [[ $(head -1 "$COMMIT_MESSAGE_FILE_PATH") == '' ]]; then + exit 0 +fi + +POSTFIX=$(git branch | grep '\*' | sed 's/* //' | sed 's/^.*\///' | sed 's/^\([^-]*-[^-]*\).*/\1/') + +COMMIT_SOURCE=$2 + +if [ "$COMMIT_SOURCE" != "merge" ]; then + if [[ "$MESSAGE" != *"[#$POSTFIX]"* ]]; then + printf "%s\n\n[#%s]" "$MESSAGE" "$POSTFIX" > "$COMMIT_MESSAGE_FILE_PATH" + fi +fi \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..87abf63 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +init: + git config core.hooksPath .githooks diff --git a/SETUP.md b/SETUP.md new file mode 100644 index 0000000..ba61ee7 --- /dev/null +++ b/SETUP.md @@ -0,0 +1,5 @@ +## Setup Git Hooks + +```bash +$ make +``` diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..608aefb --- /dev/null +++ b/setup.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +make +cat SETUP.md >> README.md +rm SETUP.md setup.sh