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 if a file of a given type is staged for commit
\CaptainHook\App\Hook\Condition\FileStaged\InDirectory Check if a file in a directory is changed
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
logic conditions
\CaptainHook\App\Hook\Condition\Logic\LogicAnd Combine multiple conditions. Only if all conditions apply the action will be executed
\CaptainHook\App\Hook\Condition\Logic\LogicOr 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 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"
      ]
    }
  ]
}

FileStaged\InDirectory

pre-commit

Expecting just the type of file you want to watch as string.

{
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\InDirectory",
      "args": [
        "src/Foo/"
      ]
    }
  ]
}

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"]
      ]
    }
  ]
}

Logic\LogicAnd

Combining multiple actions. All have to pass to execute the action.

{
  "conditions": [
    {
      "exec": "and",
      "args": [{
        "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\InDirectory",
        "args": [
          ["src/new"]
        ]
      },{
        "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
        "args": [
          ["php"]
        ]
      }]
    }
  ]
}

Logic\LogicOr

Combining multiple actions. Only one condition must apply to execute the action.

{
  "conditions": [
    {
      "exec": "or",
      "args": [{
        "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\InDirectory",
        "args": [
          ["src/new"]
        ]
      },{
        "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
        "args": [
          ["php"]
        ]
      }]
    }
  ]
}