DCO Commit Message Hook

Last modified by Craig Northway on 2018/01/22 23:11

DCO commit-msg Hook

The below script can be used as a very basic commit-msg hook to verify that all commits are signed off by the DCO. To install this copy the below file to .git/hooks/commit-msg in your local clone of the git repository. Please ensure to remove the sample .git/hooks/commit-msg.sample and ensure the new script is executable, chmod +x .git/hooks/commit-msg. It will run every commit and fail if the DCO is not present in a commit message. You could customize this hook further to check for your specific name and e-mail sign off to ensure you sign off any commits merged from other developers, see the example below.

#!/usr/bin/env bash
#
# Basic hook to check for DCO
#

commit_regex='^Signed-off-by: '
error_msg="Your commit message is not signed off with the DCO"

if ! grep -qE "$commit_regex" "$1"; then
   echo "$error_msg" >&2
   exit 1
fi

Below is a variant to address the need to sign off with a specific e-mail domain.

#!/usr/bin/env bash
#
# Basic hook to check for DCO
#

commit_regex='^Signed-off-by: .* \<.*@codeaurora.org\>'
error_msg="Your commit message is not signed off with the DCO and correct e-mail domain"

if ! grep -qE "$commit_regex" "$1"; then
   echo "$error_msg" >&2
   exit 1
fi
Tags:
Created by Craig Northway on 2017/12/06 00:26
   
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 7.4.3 - Documentation