commit
2095e34c9d
4 changed files with 49 additions and 20 deletions
25
scripts/hooks/commit-msg.checkstyle.sh
Normal file
25
scripts/hooks/commit-msg.checkstyle.sh
Normal file
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
22
scripts/hooks/pre-push.protect-master.sh
Normal file
22
scripts/hooks/pre-push.protect-master.sh
Normal file
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue