-
Notifications
You must be signed in to change notification settings - Fork 24
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
Create pre-commit hook for running tex-fmt #81
Conversation
Thanks for this. I'm not sure I understand the motivation for the However I'm keen to get pre-commit integration set up! |
"Failing" on modifying files is a requirement of pre-commit. The workflow this way is:
This way it formats the changed files automatically and gives the committer a chance to check if everything is okay. Personally I find this more comfortable than having to manually format my files (I'm lazy, I know), but whether this is the right default behavior is up to you. There are examples working similarly, like |
Thanks I understand. Since there are quite a few files changed here, perhaps you can do the following:
Feel free to suggest changes to the README.md in each PR, as you have done here, but please keep these as minimal as possible. Thanks again! |
All right, done and done. I also changed the .pre-commit-hooks.yaml so the used flag can be overwritten so everyone can choose what method is preferable to them. See the readme about it. Hit me up if you need anything else! |
Thanks, one last question: will the |
Yes! Supplying the args field overrides the hook defaults. I tested it to be extra sure. |
What I did
I wanted to create a hook for pre-commit to format my LaTeX files on every commit, however this requires that the hook return a non-0 exit code when modifying the supplied files. So I created the
--fail-on-change
flag that simply formats the files and returns 1 when any of them changed -- like some kind of hybrid between--check
and no--check
.While I was making my changes I also found a bug when running with multiple files which I fixed (more in the commit message of ea3460b).
How to try
You can either use the method written here or use it from my repo with the following
.pre-commit-config.yaml
: