Hooks
Besides the actual git hooks CaptainHook supports hooks that do not exist in git like post-change. Those hooks are called virtual hooks. Virtual hooks are hooks that get triggered by multiple git hooks. The post-change hook for example gets triggered by post-checkout, post-rewrite and post-merge. You can utilize virtual hooks to not have to copy & paste hook configurations.
- pre-commit
- pre-push
- prepare-commit-msg
- commit-message
- post-commit
- post-checkout
- post-merge
- post-rewrite
pre-commit
This hook will run before git executes a commit. Failing during this commit aborts the current commit. You can run unit tests, style checker or linter during this hook to make sure nobody commits 'broken' code.
"pre-commit": {
"actions": [
{
"run": "go test"
}
]
}
prepare-commit-msg
This hook will run before git executes a commit. Failing during this commit aborts the current commit. Here you get access to the provided git commit message to change it. This hook will not be skipped with --no-verify, so you should not use it for validation.
This can be used if you want to include details into your commit messages that you can gather automatically.
"prepare-commit-msg": {
"actions": [
{
"run": "CaptainHook::Message.InjectIssueKeyFromBranch"
}
]
}
commit-msg
This hook will run before git executes a commit. Failing during this commit aborts the current commit. Here you get access to the provided git commit message to validate it.
"commit-msg": {
"actions": [
{
"run": "CaptainHook::CaptainHook::Message.MustFollowBeamsRules"
}
]
}
pre-push
This hook will run before git executes a push. Failing during this hook aborts the current push. You can run unit tests, style checker or linter during this hook to make sure nobody pushes 'broken' code.
"pre-push": {
"actions": [
{
"run": "go test"
}
]
}
post-commit
This hook will run after a successful commit. Failing during this hook has no effect on the commit.
"post-commit": {
"actions": [
{
"run": "do/some/post-commit-action"
}
]
}
post-checkout
This hook will run after a successful checkout. Failing during this hook has no effect on the checkout.
"post-checkout": {
"actions": [
{
"run": "do/some/post-checkout-action"
}
]
}
post-merge
This hook will run after a successful merge. Failing during this hook has no effect on the merge.
"post-merge": {
"actions": [
{
"run": "do/some/post-merge-action"
}
]
}
post-rewrite
This hook will run after a successful rebase or amend. Failing during this hook has no effect on the git command.
"post-rewrite": {
"actions": [
{
"run": "do/some/post-rewrite-action"
}
]
}
Virtual hooks
virtual hook name | gets triggered by |
---|---|
post-change | post-checkout, post-merge, post-rewrite |