From 6cc95a5e47dd2c2e95ead5d2639eacf52111b64c Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 24 Jun 2025 10:57:18 +0100 Subject: [PATCH 1/3] Add a commit-msg hook to ensure commits are signed-off Signed-off-by: Philip John --- .githooks/commit-msg | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 .githooks/commit-msg 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 +} From 6b225818f5b47bb4bb116ec6b1a06a8aed10bcd2 Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 24 Jun 2025 11:16:37 +0100 Subject: [PATCH 2/3] Add a Git hook installer and handy composer setup script to run it Signed-off-by: Philip John --- bin/install-git-hooks.sh | 7 +++++++ composer.json | 3 +++ 2 files changed, 10 insertions(+) create mode 100755 bin/install-git-hooks.sh 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" From ea1ad944070d40b77bc89faefd95414a2119f66d Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 24 Jun 2025 11:17:04 +0100 Subject: [PATCH 3/3] Supplement the contributing guidelines with the new Git hook Signed-off-by: Philip John --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) 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`: