captainhookphp / captainhook

CaptainHook is a very flexible git hook manager for software developers that makes sharing git hooks with your team a breeze.
http://captainhook.info
MIT License
996 stars 86 forks source link

LogicAnd condion does not allow to combine conditions per file #206

Closed CircleCode closed 1 year ago

CircleCode commented 1 year ago

For example, I would like to run action if a php file has been modified in dir src/new/

The following example from the doc will be true if both conditions are validated

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

And that does not work?

CircleCode commented 1 year ago

And that does not work?

That does work, but that allows only the condition

any file has been modified in src/new/ AND a php file has been modified everywere

but not

a php file has been modified in src/new/”.

sebastianfeldmann commented 1 year ago

Ah got it

Yes creating a Condition that works like this looks like a good idea

{
  "conditions": [
    {
      "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged",
      "args": [{
        "inDirectory": "foo",
        "ofType": "php"
      }]
}
sebastianfeldmann commented 1 year ago

This is now fixed with the FileStaged\ThatIs condition :)