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

Explain how "run" runs whatever it is its value represents #800

Open
jcayzac opened this issue Aug 3, 2024 · 1 comment
Open

Explain how "run" runs whatever it is its value represents #800

jcayzac opened this issue Aug 3, 2024 · 1 comment
Labels
feature request A new lefthook feature description

Comments

@jcayzac
Copy link

jcayzac commented Aug 3, 2024

⚡ Summary

As far as I could see, the run documentation doesn't explain what the value for that configuration is beyond a "command", nor how Lefthook actually runs it, e.g direct invocation, though sh, through bash, etc.

Value

It's really difficult to understand what kind of command can be used for run, e.g. can pipes | be used? Or && and ||? Can the exit code $? of a command be checked with if? Are scripts even supported at all? What's the behavior of multiple lines (using run: |)? Will execution automatically stop at the first error? etc…

Behavior and configuration changes

Documenting the current behavior.

@jcayzac jcayzac added the feature request A new lefthook feature description label Aug 3, 2024
@mrexox
Copy link
Member

mrexox commented Aug 5, 2024

For macOS, Linux, FreeBSD the commands in run are executed via sh -c wrapper. On Windows commands are executed without a wrapper.

So, if you use unix-like systems you can use Bourne shell syntax including pipes, if statements, &&, etc. But if it's important for you to keep configuration runnable on Windows you should use simple commands. If you need to use scripts, you can specify them directly and choose the runner for them explicitly.

Will execution automatically stop at the first error?

Yes


I thought it was intuitive that commands should be one-liners, and scripts should live in a separate directory lefthook tracks. But it makes sense to write the docs about it, so thank you for creating this issue 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
Development

No branches or pull requests

2 participants