Empty file path with custom local hook
See original GitHub issueHi there, I’m trying to setup pre-commit for a mono-repo (backend and frontend of an app I’m using) and I’m encountering an “error” where the path passed to the hook is empty, here’s an example of hook:
repos:
- repo: local
hooks:
- id: example
name: run example
language: system
entry: bash -c 'cd backend && echo hello && echo $@ && echo "${@/backend\//./}" && exit 1'
types: [python]
files: ^backend/
The idea is to run hooks from the correct folder so they find the right configuration files 😃
This is my stage:
❯ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .pre-commit-config.yaml
modified: backend/api/schema.py
modified: frontend/components/activate-screen/modal.tsx
modified: frontend/components/add-media-card/modal.tsx
new file: frontend/components/loading.tsx
And this is the output:
❯ git commit
run example..............................................................Failed
- hook id: example
- exit code: 1
hello
Am I doing something wrong with using “$@”? Let me know if you need more information 😊
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Git pre-commit hook is not running on Windows - Stack Overflow
I set up a local repository, so there is now a '.git' directory in my project folder. I have added a '.cmd' file...
Read more >Git Hooks | Atlassian Git Tutorial
Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository. Learn what they do and how...
Read more >pre-commit
A lightweight language to forbid files by filename. The fail language is especially useful for local hooks. The entry will be printed when...
Read more >githooks Documentation - Git
Hooks are programs you can place in a hooks directory to trigger actions at certain points in git's execution. Hooks that don't have...
Read more >sam build - AWS Serverless Application Model
The sam build command processes your AWS SAM template file, application code, ... -m , --manifest PATH, The path to a custom dependency...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think if you’re trying to do it inline if you add
--
to the end it’ll work (that’ll be the “program name”) – that way your first filename doesn’t get gobbled:bash -c
shifts the arguments. thus, if pre-commit passesfoo1 foo2 foo3
as arguments,$@
will expand tofoo2 foo3
types: [python]
, thus onlybackend/api/schema.py
will be matched. this means, that$@
expands to an empty stringyou can see which arguments are passed if you use
entry: echo
and setverbose: true