]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1042] prepare-commit-msg hooks added
authorTomek Mrugalski <tomasz@isc.org>
Tue, 3 Dec 2019 15:51:18 +0000 (16:51 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 13 Dec 2019 17:38:25 +0000 (18:38 +0100)
tools/git-hooks-install [new file with mode: 0755]
tools/git-hooks/prepare-commit-msg [new file with mode: 0755]

diff --git a/tools/git-hooks-install b/tools/git-hooks-install
new file mode 100755 (executable)
index 0000000..be88593
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# This script install user-side git commit hooks. You are supposed to run it
+# only once for each repo (and very infrequently afterwards, once each time
+# the git hooks change).
+
+if test -d .git; then
+  TOPDIR=.
+else
+  TOPDIR=..
+fi
+
+GITDIR=${TOPDIR}/.git
+
+if test ! -d ${GITDIR}; then
+   echo "ERROR: Could not find ${GITDIR} in ${TOPDIR}"
+   exit -1
+fi
+
+echo "Installing hooks in ${GITDIR}/hooks"
+mkdir -p ${GITDIR}/hooks
+cp ${TOPDIR}/tools/git-hooks/prepare-commit-msg ${GITDIR}/hooks
+chmod u+x ${GITDIR}/hooks/prepare-commit-msg
diff --git a/tools/git-hooks/prepare-commit-msg b/tools/git-hooks/prepare-commit-msg
new file mode 100755 (executable)
index 0000000..13bbe84
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+BRANCH=`git branch | grep '^\*' | cut -b3-`
+
+if test "$BRANCH" == "master"; then
+    echo "ERROR: You are on branch $BRANCH"
+    echo "ERROR: You are not allowed to commit to master directly. Please follow the process"
+    echo "ERROR: (create issue, then MR for it, ...)"
+    exit 1
+fi
+
+BRANCH_NUMBER=`git branch | grep -o '^\* [0-9]*' | cut -b3-`
+/bin/echo -n "[#$BRANCH_NUMBER] " > "$1.msg"
+cat "$1" >> "$1.msg"
+mv "$1.msg" "$1"