evilmartians/lefthook

Does not work correctly if there are multiple excludes

pvcresin opened this issue · 2 comments

🔧 Summary

As the title says.

(Thank you very much for support of multiple exclude!)

Lefthook version

1.7.5 d7ae5f7

Steps to reproduce

Repository: https://github.com/pvcresin/lefthook-exclude-test

package.json

{
  "devDependencies": {
    "lefthook": "^1.7.5",
    "prettier": "^3.3.3"
  }
}

lefthook.yml

---
pre-commit:
  parallel: true
  commands:
    format:
      glob: "*.js"
      # exclude: "b.js|c.js" # worked correctly
      exclude:
        - b.js
        - c.js
      run: |
        echo {staged_files}
        npx prettier --write {staged_files}
      stage_fixed: true

If I try to commit a.js, b.js, c.js, I want to format only a.js by prettier.

exclude: “b.js|c.js” # worked correctly.
exclude: # did not seem to work correctly.
  - b.js
  - c.js

Expected results

exclude:
  - b.js
  - c.js

If I try to commit a.js, b.js, c.js, only a.js is formatted

Actual results

exclude:
  - b.js
  - c.js

If I try to commit a.js, b.js, c.js, all a.js, b.js, c.js are formatted. 😢

Possible Solution

It might be more correct to append if v did not match all globs

https://github.com/evilmartians/lefthook/pull/777/files#diff-95baf66be56f3f284ac7a6f45870dbff51131728ff6cfa163e9eac9721229697R94-R97

Logs / Screenshots

LEFTHOOK_VERBOSE=true git ...

@mrexox seems to know more about it.

Hey @pvcresin! Thank you for submitting a bug. The fix will be ready soon