Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Ensure the commit is signed-off by the author.
if ! grep -q '^Signed-off-by: ' "$1"; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rewrite this in NodeJS to remove the Bash dependency? All of the tooling already requires Node so that would work out of the box for everyone consistently.

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
}
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
7 changes: 7 additions & 0 deletions bin/install-git-hooks.sh
Original file line number Diff line number Diff line change
@@ -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."
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"lock": false
},
"scripts": {
"setup": [
"./bin/install-git-hooks.sh"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I wonder if this would be better suited for package.json since that is the canonical runner of scripts.

  2. There is git config --local core.hooksPath .githooks which would set the hooks directory and avoid the need to symlink files. This makes it work across operating systems and it is the same logic that husky uses behind the scenes. It makes is clear which hooks are available and can be enabled.

],
"test": [
"Composer\\Config::disableProcessTimeout",
"@php ./vendor/phpunit/phpunit/phpunit"
Expand Down