I'm trying to use pre-commit to manage Black as a Git pre-commit hook, but I must be doing it wrong.
In my pre-commit config file I have:
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
What I'm expecting to happen is for Black to just modify the staged file, and for the commit to succeed. Because the whole point of Black is that it auto-enforces Python code style rules, no questions asked.
What actually happens when I stage a (non-black-compliant) file and try to commit: Black goes ahead and modifies the file to make it compliant, as intended... But the problem is that it returns a "fail". So the commit fails. And then I have to unstage the file, then restage it before committing again... and only then does the commit succeed.
This is a huge annoyance and can't possibly be the intended workflow?
What am I doing wrong?
black
repository: github.com/psf/black/issues/1857 – Sticklergit add
to run black before staging; leaving the pre-commit hook as a validity check, not a formatting tool. – Pya