Conditions
Here's a list of all built-in conditions:
| All hooks | |
|---|---|
| \CaptainHook\App\Hook\Condition\Branch\On | Check if we are on a particular branch |
| \CaptainHook\App\Hook\Condition\Branch\NotOn | Check if we are not on a particular branch |
| CaptainHook.Status.OnMatchingBranch | Check if we are on a particular branch that matches a given regex |
| CaptainHook.Status.NotOnMatchingBranch | Check if we are not on a particular branch that matches a given regex |
| CaptainHook.Config.CustomValueIsTruthy | Check if a custom config is true, 1, yes or on |
| CaptainHook.Config.CustomValueIsFalsy | Check if a custom config is false, 0, no or off |
| \CaptainHook\App\Hook\Condition\Branch\Files | Check if the current branch has changed files |
| pre-commit | |
| CaptainHook.FileStaged.All | Check if all of the configured files are staged for commit |
| CaptainHook.FileStaged.Any | Check if any of the configured files is staged for commit |
| CaptainHook.FileStaged.OfType | Check if a file of a given type is staged for commit |
| CaptainHook.FileStaged.InDirectory | Check if a file in a directory is changed |
| post-checkout / post-merge / post-rewrite / pre-push | |
| CaptainHook.FileChanged.All | Check if all the configured files are changed |
| CaptainHook.FileChanged.Any | Check if any of the configured files is changed |
| CaptainHook.FileChanged.OfType | Check if changes to a type of file will be pushed |
| logic conditions | |
| CaptainHook.Logic.And | Combine multiple conditions. Only if all conditions apply the action will be executed |
| CaptainHook.Logic.Or | Combine multiple conditions. If one condition applies the action will be executed |
You can build your own conditions. You can either use simple scripts or binaries which must return an exit code. The exit code 0 means the condition applies; any exit code other than 0 means the condition does not apply.
Or you can build custom PHP Conditions. For an exact guide have a look at the "how to extend CaptainHook" section.
OnBranch
all hooks
This Condition expects just one argument, the name of the branch.
{
"conditions": [
{
"exec": "CaptainHook.Status.OnBranch",
"args": [
"main"
]
}
]
}
NotOnBranch
all hooks
This Condition expects just one argument, the name of the branch.
{
"conditions": [
{
"exec": "CaptainHook.Status.NotOnBranch",
"args": [
"main"
]
}
]
}
OnMatchingBranch
all hooks
This Condition expects just one argument, the regex to match the branch.
{
"conditions": [
{
"exec": "CaptainHook.Status.OnMatchingBranch",
"args": [
"#feature/[a-z0-9\-_]+#i"
]
}
]
}
NotOnMatchingBranch
all hooks
This Condition expects just one argument, the regex to match the branch.
{
"conditions": [
{
"exec": "CaptainHook.Status.NotOnMatchingBranch",
"args": [
"#feature/[a-z0-9\-_]+#i"
]
}
]
}
CustomValueIsTruthy
all hooks
This Condition expects just one argument, the name of the custom config value to check.
{
"conditions": [
{
"exec": "CaptainHook.Config.CustomValueIsTruthy",
"args": [
"MY_CONFIG_VALUE"
]
}
]
}
CustomValueIsFalsy
all hooks
This Condition expects just one argument, the name of the custom config value to check.
{
"conditions": [
{
"exec": "CaptainHook.Config.CustomValueIsFalsy",
"args": [
"MY_CONFIG_VALUE"
]
}
]
}
Branch files changed
all hooks
This Condition accepts an options object, all values are optional.
This will not work in the main branch and should most likely combined with a NotOn condition
If you don't provide the compare-to option, it will try to figure out the branching point using the reflog.
{
"conditions": [
{
"exec": "CaptainHook\\App\\Hook\\Condition\\Branch\\Files",
"args": [
{"compared-to": "main", "of-type": "php", "in-dir": "foo/"}
]
}
]
}
FileStaged\All
pre-commit
Expecting a list of file names or pattern.
{
"conditions": [
{
"exec": "CaptainHook.FileStaged.All",
"args": [
["foo.html", "bar.html", "*.php"]
]
}
]
}
FileStaged\Any
pre-commit
Expecting a list of file names or pattern.
{
"conditions": [
{
"exec": "CaptainHook.FileStaged.Any",
"args": [
["foo.html", "bar.html", "*.php"]
]
}
]
}
FileStaged\OfType
pre-commit
Expecting just the type of file you want to watch as string.
{
"conditions": [
{
"exec": "CaptainHook.FileStaged.OfType",
"args": [
"php"
]
}
]
}
FileStaged\InDirectory
pre-commit
Expecting just the type of file you want to watch as string.
{
"conditions": [
{
"exec": "CaptainHook.FileStaged.InDirectory",
"args": [
"src/Foo/"
]
}
]
}
FileChanged\All
post-checkout post-merge
Expecting a list of file names or pattern.
{
"conditions": [
{
"exec": "CaptainHook.FileChanged.All",
"args": [
["foo.html", "bar.html", "*.php"]
]
}
]
}
FileChanged\Any
post-checkout post-merge
Expecting a list of file names or pattern.
{
"conditions": [
{
"exec": "CaptainHook.FileChanged.Any‚",
"args": [
["foo.html", "bar.html", "*.php"]
]
}
]
}
FileChanged\OfType
pre-push
Expecting just the type of file you want to watch as string.
{
"conditions": [
{
"exec": "CaptainHook.FileChanged.OfType",
"args": [
"php"
]
}
]
}
Logic\LogicAnd
Combining multiple conditions. All must pass to execute the action.
{
"conditions": [
{
"exec": "and",
"args": [{
"exec": "CaptainHookFileStaged.InDirectory",
"args": [
["src/new"]
]
},{
"exec": "CaptainHook.FileStaged.OfType",
"args": [
["php"]
]
}]
}
]
}
Logic\LogicOr
Combining multiple conditions. Only one condition must apply to execute the action.
{
"conditions": [
{
"exec": "or",
"args": [{
"exec": "CaptainHook.FileStaged.InDirectory",
"args": [
["src/new"]
]
},{
"exec": "CaptainHook.FileStaged.OfType",
"args": [
["php"]
]
}]
}
]
}