Skip to content

Git hooks

pre-commit

If you'd like your code to be automatically checked pre-commit you can copy a Git hook to your Git hooks directory, in the carandclassic repository:

ln -fs "$PWD"/.githooks/pre-commit "$PWD"/.git/hooks/pre-commit

This will set up a pre-commit hook which checks the style of any PHP files modified in that commit.

This uses both PHP_CodeSniffer and PHP-CS-Fixer.

If you need to skip a pre-commit Git hook for whatever reason, you can run git commit --no-verify or uncheck “run Git hooks” from the PhpStorm GUI (or equivalent in another IDE).

Note that if you are using an IDE or other GUI for Git commits, you will need to check the console for details if a Git commit fails.

Example on PhpStorm:
PhpStorm git commit console

prepare-commit-msg

ln -fs "$PWD"/.githooks/prepare-commit-msg "$PWD"/.git/hooks/prepare-commit-msg

Automatically prefixes commit messages with the issue ID that is used in the branch name. This only happens if the commit message does not already start with a prefix.

e.g. a message add translations in the sc-1337/search-filters branch will be prefixed and become [SC-1337] add translations.

This is useful when browsing the commit history, running git blame or for associating commits to issues.