summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-04 19:37:57 +0100
committerGitHub <noreply@github.com>2018-01-04 19:37:57 +0100
commit2095e34c9d14097b7c7625f3629cbdfe5ff5c752 (patch)
tree4f594dd50edee47786dd17b68b5a0f45bda618ea
parent5aeaacc31705ffc1a461f4c99eebf050974f028d (diff)
parent806e706087f27463b58365832be1e442f2b1afa6 (diff)
downloadimag-2095e34c9d14097b7c7625f3629cbdfe5ff5c752.zip
imag-2095e34c9d14097b7c7625f3629cbdfe5ff5c752.tar.gz
Merge pull request #1194 from matthiasbeyer/hook-scripts
Hook scripts
-rw-r--r--scripts/hooks/commit-msg.checkstyle.sh25
-rw-r--r--scripts/hooks/pre-push.fixup-warn.sh20
-rw-r--r--scripts/hooks/pre-push.protect-master.sh22
-rw-r--r--scripts/signed-off-by-in-branch.sh2
4 files changed, 49 insertions, 20 deletions
diff --git a/scripts/hooks/commit-msg.checkstyle.sh b/scripts/hooks/commit-msg.checkstyle.sh
new file mode 100644
index 0000000..0ba89e3
--- /dev/null
+++ b/scripts/hooks/commit-msg.checkstyle.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+#
+# An hook script to check the commit message for style
+#
+# To enable this hook, copy this file to ".git/hooks/commit-msg" and make it
+# executable.
+
+. git-sh-setup
+
+
+#
+#
+# Check for "WIP" in commit message and add "[skip ci]" if commit message
+# contains a WIP.
+#
+#
+
+if grep -q -i -e "WIP" -e "work in progress" $1; then
+ read -p "You're about to add a WIP commit, do you want to run the CI? [y|n] " -n 1 -r < /dev/tty
+ echo
+ if echo $REPLY | grep -E '^[Nn]$' > /dev/null; then
+ sed -i '1,1s,.*,[ci skip] &,' $1
+ fi
+fi
+
diff --git a/scripts/hooks/pre-push.fixup-warn.sh b/scripts/hooks/pre-push.fixup-warn.sh
index 3ad7233..77a2c11 100644
--- a/scripts/hooks/pre-push.fixup-warn.sh
+++ b/scripts/hooks/pre-push.fixup-warn.sh
@@ -14,10 +14,8 @@ z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha
do
- if [ "$local_sha" = $z40 ]
+ if [ "$local_sha" != $z40 ]
then
- # Branch is deleted, nothing to check here, move along.
- else
if [ "$remote_sha" = $z40 ]
then
# New branch, examine all commits
@@ -36,22 +34,6 @@ do
# TO NOT ONLY WARN BUT ABORT UNCOMMENT THE NEXT LINE
# exit 1
fi
-
- # Check for commits without sign-off
- if [ "$remote_sha" = $z40 ]; then
- # New branch is pushed, we only want to check commits that are not
- # on master.
- range="$(git merge-base master "$local_sha")..$local_sha"
- fi
- while read ref; do
- msg=$(git log -n 1 --format=%B "$ref")
- if ! grep -q '^Signed-off-by: ' <<<"$msg"; then
- echo >&2 "Unsigned commit $ref"
- exit 1
- fi
- done < <(git rev-list "$range")
- # The process substitution above is a hack to make sure loop runs in
- # the same shell and can actually exit the whole script.
fi
done
diff --git a/scripts/hooks/pre-push.protect-master.sh b/scripts/hooks/pre-push.protect-master.sh
new file mode 100644
index 0000000..c659a0d
--- /dev/null
+++ b/scripts/hooks/pre-push.protect-master.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+#
+# The following snippet can be used to WARN about pushing to master
+#
+# Aborting the push is possible
+#
+
+protected_branch='master'
+current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
+
+if [ $protected_branch = $current_branch ]; then
+ read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty
+ echo
+ if echo $REPLY | grep -E '^[Yy]$' > /dev/null; then
+ exit 0 # push will execute
+ fi
+ exit 1 # push will not execute
+else
+ exit 0 # push will execute
+fi
+
diff --git a/scripts/signed-off-by-in-branch.sh b/scripts/signed-off-by-in-branch.sh
index 480f5a0..a7a4945 100644
--- a/scripts/signed-off-by-in-branch.sh
+++ b/scripts/signed-off-by-in-branch.sh
@@ -12,6 +12,6 @@ then
echo >&2 "All good"
else
echo -en >&2 "${RED}Got $faulty non Signed-off-by commits${NORMAL}"
- echo -e >&2 "${RED}between $1 and $2${NORMAL}"
+ echo -e >&2 "${RED} between $1 and $2${NORMAL}"
fi