Documentation/Feature request: `git stash` on `pre-commit` and `pre-push`
I love how fast lefthook is, but a problem I'm running into is that my hooks will sometimes fail locally even though they should pass, or pass locally but fail on our CI server because lefthook doesn't automatically stash uncommitted changes before running the hooks.
Is there an easy way to configure this manually? (I didn't see one in the examples) Ideally I'd still be able to have parallel: true, so wouldn't rely on an order of operations.
Hi @hbergren Take a look at this Discourse examples. Config: https://github.com/discourse/discourse/blob/master/lefthook.yml CI: https://github.com/discourse/discourse/blob/0872a1182d5702cf24bfce8958fc7cf12339c5ae/.travis.yml#L77
I see. So the only way to do this is to write custom linting scripts in lefthook.yml that only run on staged_files or some custom selection of files?
I was hoping for an easy way to stash uncommitted changes before and after a hook so that I could let my script functionality live in package.json and do something like this:
pre-push:
parallel: true
commands:
eslint:
tags: style
run: npm run lintNoFix
...
where in package.json: "lintNoFix": "eslint . --ext .ts --max-warnings 0 && prettier --check '**/*.{md,json}'",.
But it sounds like the only solution as of right now is to write out something like this:
pre-push:
parallel: true
commands:
prettier:
tags: style
files: git diff --name-only HEAD @{push}
glob: '*.{md,json}'
run: npx prettier {files}
eslint:
tags: style
files: git diff --name-only HEAD @{push}
glob: '*.ts'
run: npx eslint --max-warnings 0 {files}
Is that correct?
Yea, for my point of view it very strange to commit something after auto-fixers without observing changes. A lot of them could broke your code or provide unexpected behaviour.
That is why lefthook doesn't provide that behavior out of the box.