Skip to content
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

feat: allow to define lefthook executable or command #927

Conversation

mrexox
Copy link
Member

@mrexox mrexox commented Jan 14, 2025

Closes #443

⚡ Summary

There are two scenarios when you want to specify the lefthook executable or lefthook command:

  1. You want to make sure developers in your project use the same lefthook version as installed in your project dependencies (makes sense when installing lefthook via npm, Ruby gems, PyPi)
  2. You use PnP loader and have your package.json with lefthook dependency in a subdir. Currently there's no way to correctly do cd subdir; yarn run lefthook. This option can help with this.

The other special case is: you want to use your own lefthook executable defined in lefthook-local.yml (for whatever reason).

  • Add lefthook field to the top-level config options
  • Update hook template. Strip and replace newlines with ';' since the value will be wrapped with sh -c
  • Add tests
  • Add docs

So, examples:

Some hard-coded binary

# lefthook.yml

lefthook: /usr/bin/lefthook

pre-commit:
  jobs:
    - run: echo {staged_files}

Some hidden package

# lefthook.yml

lefthook: |
  cd subdir
  yarn run lefthook

pre-commit:
  jobs:
    - run: echo {staged_files}

Force using lefthook gem

# lefthook.yml

lefthook: bundle exec lefthook

pre-commit:
  jobs:
    - run: echo {staged_files}

@mrexox mrexox marked this pull request as ready for review January 14, 2025 14:57
@mrexox mrexox merged commit 9e02365 into evilmartians:master Jan 14, 2025
12 checks passed
@mrexox mrexox deleted the feat/allow-to-define-lefthook-executable-or-command branch January 14, 2025 15:13
Copy link

@fmal fmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lefthook's location is ignored in the hooks in a monorepo
2 participants