It seems that in https://github.com/pre-commit/pre-commit/issues/285 you made it so that when a tool like yapf formats code inline pre-commit will always mark the check as failed, because files were changed. Is this correct?
If so, funnily enough the behaviour I'm looking for is the exact thing you felt was a "fix". I'd like this to be able to pass:
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /Users/jasonkuhrt/.cache/pre-commit/patch1525490932.
yapf.....................................................................Failed
hookid: yapf
Files were modified by this hook.
[INFO] Restored changes from /Users/jasonkuhrt/.cache/pre-commit/patch1525490932.
I suppose that would require pre-commit to stage the auto formatted changes automatically too.
Any chance of supporting this? Its how pretty-quick works for example.
pre-commit itself will never touch the staging area. These are good ways to silently break commits. In my mind this is one of the worst things that lint-staged does and suggests -- hooks are very frequently not perfect and magically changing what's being committed should not be taken lightly.
That said, if you would like to foot gun, your hook can call git add -u and pre-commit won't know any better :) a sketch of that (untested, discouraged)
- id: yapf
entry: bash -c 'yapf "$@"; git add -u' --
(note: using bash will potentially reduce portability)
Thanks for the tip! It doesn鈥檛 have to be a foot gun. For example Black can compare the AST before/after if one is untrustful for some reason. And there can always be checks at the CI level.
Most helpful comment
Thanks for the tip! It doesn鈥檛 have to be a foot gun. For example Black can compare the AST before/after if one is untrustful for some reason. And there can always be checks at the CI level.