Unexpected behaviour of option root #574
-
Hi, I noticed a unexpected behavior when using the property core and after reading the docs and old issues/discussions I don't know if it is working as intended or if it is a bug. I'm using tconfiguration file Below you can find the configuration file used for lefthook and the structure of my code base. pre-push:
parallel: true
commands:
run-e2e-tests:
root: core
run: yarn test:e2e tree -d -L 1
.
├── artifacts
├── core
├── e2e-tests
├── examples
└── jekyll If I edit a file that is not in the core folder and try to push the commit, the pre-push command is skipped. > lefthook run -v pre-push
...
│ [lefthook] cmd: [sh -c git diff --name-only HEAD origin/main]
│ [lefthook] dir: /workspaces/TerraApprove
│ [lefthook] err: <nil>
│ [lefthook] out: e2e-tests/suites/simple/simple.bats
│ [lefthook] files before filters:
[e2e-tests/suites/simple/simple.bats]
│ [lefthook] files after filters:
[]
│ run-e2e-tests (skip) no matching push files
... Instead if the file is in the core folder, the hook run as expected. > lefthook run -v pre-push
...
│ [lefthook] cmd: [sh -c git diff --name-only HEAD origin/main]
│ [lefthook] dir: /workspaces/TerraApprove
│ [lefthook] err: <nil>
│ [lefthook] out: core/new-test.bats
│ [lefthook] files before filters:
[core/new-test.bats]
│ [lefthook] files after filters:
[.//new-test.bats]
... As far I understood from the README and the docs, I would expect the root property to only affect the folder in which the command is run and not to apply additional filters to the files that should trigger the hooks. Am I wrong ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! A very good question, and yes, It looks like you just want the command to be run from another folder but keep files unfiltered. Right now this can't be easily configured but I can suggest you something like this: pre-push:
parallel: true
commands:
run-e2e-tests:
run: lefthook run e2e-tests
e2e-tests:
parallel: true
commands:
root: core
run: yarn test:e2e So, here is a If you want to have this behavior of |
Beta Was this translation helpful? Give feedback.
Hey! A very good question, and yes,
root
is also used for implicit filtering, because lefthook assumes that if you want the command to be run in a certain root folder, you care only about files in this directory. I will edit the docs to include this behavior description.It looks like you just want the command to be run from another folder but keep files unfiltered. Right now this can't be easily configured but I can suggest you something like this:
So, here is a
pre-push
hook that doesn't use any filters, so nothing…