diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 00000000..79b26dc8 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,14 @@ +#!/bin/sh + +# Ensure the commit is signed-off by the author. +if ! grep -q '^Signed-off-by: ' "$1"; then + echo >&2 "Commit message must be signed off by the author." + exit 1 +fi + +# Catch duplicate Signed-off-by lines. +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3039cec..7424e36c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,8 @@ $ git commit -s -m 'My commit message.' **Please Note:** This is adding a _sign-off_ to the commit, which is not the same as *signing* your commits (which involves GPG keys). +Alternatively, run `composer run setup` to install a git hook which will automatically reject your commits if they are not signed off. + ## Development Environment This plugin is ready to use with wp-env for local development, with a default configuration included in the repository. `npm run env` is an alias for `wp-env`: diff --git a/bin/install-git-hooks.sh b/bin/install-git-hooks.sh new file mode 100755 index 00000000..a67c7bc4 --- /dev/null +++ b/bin/install-git-hooks.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e +# +# Create our distribution zips. + +# Create a link to our commit-msg hook. +ln -s -f ../../.githooks/commit-msg .git/hooks/commit-msg +echo "Installed commit-msg hook." diff --git a/composer.json b/composer.json index 3ae2707c..5ea67bfc 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,9 @@ "lock": false }, "scripts": { + "setup": [ + "./bin/install-git-hooks.sh" + ], "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit"