Skip to content

Instantly share code, notes, and snippets.

@tombentley
Created January 9, 2020 10:45
Show Gist options
  • Save tombentley/332f8c05867410fc24496b8b6b3df4c6 to your computer and use it in GitHub Desktop.
Save tombentley/332f8c05867410fc24496b8b6b3df4c6 to your computer and use it in GitHub Desktop.
#!/usr/bin/sh
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# To enable this hook, rename this file to "commit-msg".
# Uncomment the below to add a Signed-off-by line to the message.
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
# hook is more suited to it.
#
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
# This example catches duplicate Signed-off-by lines.
# check if stdout is a terminal...
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold="$(tput bold)"
underline="$(tput smul)"
standout="$(tput smso)"
normal="$(tput sgr0)"
black="$(tput setaf 0)"
red="$(tput setaf 1)"
green="$(tput setaf 2)"
yellow="$(tput setaf 3)"
blue="$(tput setaf 4)"
magenta="$(tput setaf 5)"
cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 "${red}ERROR: Duplicate Signed-off-by lines.${normal}"
exit 1
}
grep -q '^Signed-off-by: ' "$1" || {
echo >&2 "${red}ERROR: Missing Signed-off-by line.${normal}"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment