Conditions

Here's a list of all built-in conditions

All hooks
\CaptainHook\App\Hook\Condition\OnBranch Check if we are on a particular branch
pre-commit
\CaptainHook\App\Hook\Condition\FileStaged\All Check if all of the configured files are staged for commit
\CaptainHook\App\Hook\Condition\FileStaged\Any Check if any of the configured files is staged for commit
\CaptainHook\App\Hook\Condition\FileStaged\OfType Check is a file of a given type is staged for commit
post-checkout / post-merge
\CaptainHook\App\Hook\Condition\FileChange\All Check if all of the configured files are changed
\CaptainHook\App\Hook\Condition\FileChange\Any Check if any of the configured files is changed

You can build your own conditions. You can either use simple scripts or binaries which have to return an exit code. The exit code 0 means the condition applies, any exit code other then 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\\App\\Hook\\Condition\\OnBranch",
      "args": [
        "master"
      ]
    }
  ]
}

FileStaged\All

pre-commit

Expecting a list of file names or pattern.

{
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\All",
      "args": [
        ["foo.html", "bar.html", "*.php"]
      ]
    }
  ]
}

FileStaged\Any

pre-commit

Expecting a list of file names or pattern.

{
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\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\\App\\Hook\\Condition\\FileStaged\\OfType",
      "args": [
        "php"
      ]
    }
  ]
}

FileChanged\All

post-checkout post-merge

Expecting a list of file names or pattern.

{
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\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\\App\\Hook\\Condition\\FileChanged\\Any‚",
      "args": [
        ["foo.html", "bar.html", "*.php"]
      ]
    }
  ]
}