Merge pull request #1194 from matthiasbeyer/hook-scripts

Hook scripts
This commit is contained in:
Matthias Beyer 2018-01-04 19:37:57 +01:00 committed by GitHub
commit 2095e34c9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 20 deletions

View 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

View file

@ -14,10 +14,8 @@ z40=0000000000000000000000000000000000000000
while read local_ref local_sha remote_ref remote_sha while read local_ref local_sha remote_ref remote_sha
do do
if [ "$local_sha" = $z40 ] if [ "$local_sha" != $z40 ]
then then
# Branch is deleted, nothing to check here, move along.
else
if [ "$remote_sha" = $z40 ] if [ "$remote_sha" = $z40 ]
then then
# New branch, examine all commits # New branch, examine all commits
@ -36,22 +34,6 @@ do
# TO NOT ONLY WARN BUT ABORT UNCOMMENT THE NEXT LINE # TO NOT ONLY WARN BUT ABORT UNCOMMENT THE NEXT LINE
# exit 1 # exit 1
fi 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 fi
done done

View 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

View file

@ -12,6 +12,6 @@ then
echo >&2 "All good" echo >&2 "All good"
else else
echo -en >&2 "${RED}Got $faulty non Signed-off-by commits${NORMAL}" 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 fi