25 lines · 1.2 KB · Text
RawDownload
#!/bin/sh# A sample hook to check commit messages created by `git commit`################################################################## This example script checks commit messages for duplicate `Signed-off-by`# lines and rejects the commit if these are present.## It is called by "git commit" with a single argument: the name of the file# that contains the final commit message, which would be used in the commit.# A a non-zero exit status after issuing an appropriate message stops the operation.# The hook is allowed to edit the commit message file by rewriting the file# containing it.## To enable this hook remove the `.sample` suffix from this file entirely. # Check for duplicate Signed-off-by lines in the commit message.# The following command uses grep to find lines starting with "Signed-off-by: "# in the commit message file specified by the first argument `$1`.# It then sorts the lines, counts the number of occurrences of each line,# and removes any lines that occur only once.# If there are any remaining lines, it means there are duplicate Signed-off-by lines.test "$(grep '^Signed-off-by: ' "$1" | sort | uniq -c | sed -e '/^[ 	]*1[ 	]/d')" = "" || {	echo "Remove duplicate Signed-off-by lines and repeat the commit." 1>&2	exit 1}