commit
c870a0a240
5 changed files with 175 additions and 0 deletions
33
scripts/hooks/applypatch-msg.check-signed-off.sh
Normal file
33
scripts/hooks/applypatch-msg.check-signed-off.sh
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# An hook script to check the commit log message taken by
|
||||||
|
# applypatch from an e-mail message for proper "Signed-off-by" line(s).
|
||||||
|
#
|
||||||
|
# To enable this hook, copy this file to ".git/hooks/applypatch-msg" and make it
|
||||||
|
# executable.
|
||||||
|
|
||||||
|
#
|
||||||
|
# This hook is used when applying patches which are send via mail, to verify the
|
||||||
|
# Signed-off-by line is in the commit message.
|
||||||
|
#
|
||||||
|
|
||||||
|
. git-sh-setup
|
||||||
|
|
||||||
|
RED='\e[0;31m' # Red
|
||||||
|
YELLOW='\e[0;33m' # Yellow
|
||||||
|
NORMAL='\e[0m' # Text Reset
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
echo -e >&2 "${YELLOW}$*${DEFAULT}"
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
echo -e >&2 "${RED}$*${DEFAULT}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
headline=$(head -n 1 $1 | wc -c)
|
||||||
|
[[ $headline -gt 50 ]] && warn "Headline of patch longer than 50 chars"
|
||||||
|
|
||||||
|
grep "^Signed-off-by" $1 >/dev/null 2>/dev/null && abort "No Signed-off-by line"
|
||||||
|
|
17
scripts/hooks/pre-commit.signoffby-missing-warn.sh
Normal file
17
scripts/hooks/pre-commit.signoffby-missing-warn.sh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# The following snippet can be used to _WARN_ if a Signed-off-by line is missing
|
||||||
|
# in the commit message
|
||||||
|
#
|
||||||
|
|
||||||
|
RED='\e[0;31m' # Red
|
||||||
|
NORMAL='\e[0m' # Text Reset
|
||||||
|
|
||||||
|
if [ "1" != "$(grep -c '^Signed-off-by: ' "$1")" ]; then
|
||||||
|
printf >&2 "%sMissing Signed-off-by line.%s\n" "$RED" "$NORMAL"
|
||||||
|
|
||||||
|
# To not only warn, but abort the commit, uncomment the next line
|
||||||
|
# exit 1
|
||||||
|
fi
|
||||||
|
|
58
scripts/hooks/pre-push.fixup-warn.sh
Normal file
58
scripts/hooks/pre-push.fixup-warn.sh
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# The following snippet can be used to WARN about "!fixup" / "WIP" / "TMP"
|
||||||
|
# commits when pushing
|
||||||
|
#
|
||||||
|
# Aborting the push is possible
|
||||||
|
#
|
||||||
|
|
||||||
|
remote="$1"
|
||||||
|
url="$2"
|
||||||
|
|
||||||
|
z40=0000000000000000000000000000000000000000
|
||||||
|
|
||||||
|
while read local_ref local_sha remote_ref remote_sha
|
||||||
|
do
|
||||||
|
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
|
||||||
|
range="$local_sha"
|
||||||
|
else
|
||||||
|
# Update to existing branch, examine new commits
|
||||||
|
range="$remote_sha..$local_sha"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for WIP commit
|
||||||
|
commit=$(git rev-list -n 1 --grep '^WIP|^TMP|!fixup' "$range")
|
||||||
|
if [ -n "$commit" ]
|
||||||
|
then
|
||||||
|
echo >&2 "Found WIP commit in $local_ref, not pushing"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
exit 0
|
50
scripts/hooks/pre-push.signoffby-missing-warn.sh
Normal file
50
scripts/hooks/pre-push.signoffby-missing-warn.sh
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# The following snippet can be used to WARN about a missing signed-off-by line
|
||||||
|
# in commits when pushing
|
||||||
|
#
|
||||||
|
# Aborting the push is possible
|
||||||
|
#
|
||||||
|
|
||||||
|
remote="$1"
|
||||||
|
url="$2"
|
||||||
|
|
||||||
|
z40=0000000000000000000000000000000000000000
|
||||||
|
|
||||||
|
while read local_ref local_sha remote_ref remote_sha
|
||||||
|
do
|
||||||
|
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
|
||||||
|
range="$local_sha"
|
||||||
|
else
|
||||||
|
# Update to existing branch, examine new commits
|
||||||
|
range="$remote_sha..$local_sha"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
# TO NOT ONLY WARN BUT ABORT UNCOMMENT THE NEXT LINE
|
||||||
|
# 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
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
17
scripts/signed-off-by-in-branch.sh
Normal file
17
scripts/signed-off-by-in-branch.sh
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Checks whether all commit between $1 and $2 have a signed-off-by line
|
||||||
|
|
||||||
|
RED='\e[0;31m' # Red
|
||||||
|
NORMAL='\e[0m' # Text Reset
|
||||||
|
|
||||||
|
faulty=$(git rev-list --grep "Signed-off-by" --invert-grep $1..$2 | wc -l)
|
||||||
|
|
||||||
|
if [[ $faulty -eq 0 ]]
|
||||||
|
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}"
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue