evilmartians / lefthook

Fast and powerful Git hooks manager for any type of projects.
MIT License
4.93k stars 215 forks source link

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

Open jcayzac opened 3 months ago

jcayzac commented 3 months ago

:zap: 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.

mrexox commented 3 months ago

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 🙏