-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Also glob commands without templates & files
#595
base: master
Are you sure you want to change the base?
Also glob commands without templates & files
#595
Conversation
Commands that neither had templates in `run` nor `files` didn't apply file globs, even if the `--all-files` CLI param was set
7277a40
to
a972e07
Compare
a972e07
to
0606c3f
Compare
Could you please provide an example usage with the hook? It feels like instead of replacing |
post-build:
commands:
clippy:
files: git diff --name-only --staged # remove this line
glob: '*.rs'
run: cargo clippy --all-targets --future-incompat-report -- -D warnings 2> /dev/null Without the $ git ls-files --cached --exclude-standard | grep -E '.rs$' | wc -l
3
$ git diff --name-only --cached | grep -E '.rs$' | wc -l
0
$ lefthook run -vvvv post-build
lefthook run -vvvv post-build
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: /Users/dummy/dummy
│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info
│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git
╭──────────────────────────────────────╮
│ 🥊 lefthook v1.5.5 hook: post-build │
╰──────────────────────────────────────╯
┃ clippy ❯
────────────────────────────────────
summary: (done in 0.58 seconds)
🥊 clippy I have done more tests but it's a bit of hassle to replicate and set up without risking my work. |
@sanmai-NL, this PR adds too specific changes to the lefthook processing. I am pretty sure that 99% of lefthook users don't need handling for the all files including untracked. But if I merge it I will have to support this feature which I feel can be implementing via a small hack to configuration. Implicit filtering was added only for I can suggest you a workaround many users (including me) were using for the purpose you described: # lefthook.yml
pre-build:
commands:
clippy:
files: git diff --name-only --staged # remove this line
glob: '*.rs'
run: cargo clippy --all-targets --future-incompat-report -- -D warnings 2> /dev/null || echo {files} >/dev/null This Thank you for providing this change. I learned a new use case of lefthook. I hope I could suggest a useful workaround. I'm sorry that I can't accept this change to the codebase. |
This workaround is not cross-OS compatible. The main selling point of Lefthook is not Git hooks. I can create those with a custom script. But having a Git hook collection that works cross-OS without having write and understand complex source code if team members want to learn what's happening. |
@sanmai-NL , if you keep |
Closes # (issue)
⚡ Summary
Commands that neither had templates in
run
norfiles
didn't apply file globs, even if the--all-files
orall-including-untracked-files
CLI param was set. Applying globs is useful to limit commands that run on a fixed path (e.g.,src/
) and don't use templates, but should only run if relevant paths have changed.☑️ Checklist
Please merge #594 first.