From 8832a17f12995c48b9c61194085202fa0abf84bb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 11:03:18 +0100 Subject: [PATCH 1/5] Add script to check commit message style --- scripts/hooks/commit-msg.checkstyle.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 scripts/hooks/commit-msg.checkstyle.sh diff --git a/scripts/hooks/commit-msg.checkstyle.sh b/scripts/hooks/commit-msg.checkstyle.sh new file mode 100644 index 00000000..e1644f6d --- /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 + echo "[skip ci]" >> $1 + fi +fi + From 85db1d5f02fabf03d2cfb5f4bbf662316f69e55d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 11:03:31 +0100 Subject: [PATCH 2/5] Add script to warn about pushing to master --- scripts/hooks/pre-push.protect-master.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/hooks/pre-push.protect-master.sh diff --git a/scripts/hooks/pre-push.protect-master.sh b/scripts/hooks/pre-push.protect-master.sh new file mode 100644 index 00000000..c659a0d9 --- /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 + From 2fd6a701aeed4fbff3e8f5c3207e1cfcc2a2dd5f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 11:15:47 +0100 Subject: [PATCH 3/5] Fix if-else for empty if branch --- scripts/hooks/pre-push.fixup-warn.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/hooks/pre-push.fixup-warn.sh b/scripts/hooks/pre-push.fixup-warn.sh index 3ad7233e..3f0c393e 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 From db33d46608afbe95538af331a7571efd0d0c5be9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 11:24:16 +0100 Subject: [PATCH 4/5] Fix spacing --- scripts/hooks/pre-push.fixup-warn.sh | 16 ---------------- scripts/signed-off-by-in-branch.sh | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/scripts/hooks/pre-push.fixup-warn.sh b/scripts/hooks/pre-push.fixup-warn.sh index 3f0c393e..77a2c112 100644 --- a/scripts/hooks/pre-push.fixup-warn.sh +++ b/scripts/hooks/pre-push.fixup-warn.sh @@ -34,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/signed-off-by-in-branch.sh b/scripts/signed-off-by-in-branch.sh index 480f5a0a..a7a49452 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 From 806e706087f27463b58365832be1e442f2b1afa6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 4 Jan 2018 11:25:05 +0100 Subject: [PATCH 5/5] Prepend the skip-line to the first line --- scripts/hooks/commit-msg.checkstyle.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/hooks/commit-msg.checkstyle.sh b/scripts/hooks/commit-msg.checkstyle.sh index e1644f6d..0ba89e34 100644 --- a/scripts/hooks/commit-msg.checkstyle.sh +++ b/scripts/hooks/commit-msg.checkstyle.sh @@ -19,7 +19,7 @@ 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 - echo "[skip ci]" >> $1 + sed -i '1,1s,.*,[ci skip] &,' $1 fi fi