question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty file path with custom local hook

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
asottilecommented, Dec 23, 2020

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:

    entry: bash -c '...' --
1reaction
paulhfischercommented, Dec 23, 2020
  • bash -c shifts the arguments. thus, if pre-commit passes foo1 foo2 foo3 as arguments, $@ will expand to foo2 foo3
  • you have types: [python], thus only backend/api/schema.py will be matched. this means, that $@ expands to an empty string

you can see which arguments are passed if you use entry: echo and set verbose: true

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found