Using bump2version and pre-commit hooksSee original GitHub issue
I have been using bump2version for a while. Thank you for maintaining it. Most recently, I added pre-commit hooks to my workflow. Now, my bumpversion commands are always failing since I think it interferes with the pre-commit hooks.
I am using bumpversion’s
--no-commit flag for now and then commit manually. Is there a way to make them both work together ?
Here’s my bumpversion config:
[bumpversion] current_version = 1.0.0 commit = True tag = True
And here’s my pre commit hook config:
repos: - repo: git://github.com/pre-commit/pre-commit-hooks rev: v1.4.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace - id: check-case-conflict - id: check-merge-conflict - id: check-yaml args: ['--unsafe'] - id: detect-private-key - id: forbid-new-submodules - id: check-json - id: pretty-format-json - id: check-added-large-files - id: flake8 - repo: git://github.com/CuriousLearner/pre-commit-python-sorter sha: 5294cde9d51cff119af537e987c30c320e9fbe2f hooks: - id: python-import-sorter args: ['--silent-overwrite'] - repo: https://github.com/psf/black rev: stable hooks: - id: black
Let me know if you need more information from me.
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
Maybe some more info since I also have problems with pre-commit hooks and bumpversion.
More specifically my problem is connected to the
fix-trailing-whitespace hook. I configure bumpversion in
setup.cfg in a python project. This means there are other sections, sometimes containing lines like these:
[flake8] exclude = .git __pycache__
Bumpversion seems to add whitespace after
exclude = which the
fix-trailing-whitespace doesn’t like. This causes an error since the pre-commit hooks obviously fail (bumpversion adds whitespace, hooks remove whitespace)
Maybe the original author has similar problems.
Edit: The version I am using is
bumpversion: v1.0.0 (using Python v3.6.9)
Another workaround is to exclude
setup.cfg from the hook in your
- repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 hooks: - id: trailing-whitespace exclude: setup.cfg
But yeah, this isn’t ideal, and it would be nice if bumpversion didn’t modify any lines it doesn’t need to. Even without the hook, if I edit
setup.cfg manually my editor is currently configured to trim trailing whitespace, so that means the diff on a commit where I’m editing
setup.cfg is a bit noisier because of the extra whitespace. What’s worse is if I trim the whitespace manually, the next time bumpversion processes the file it’ll put the spaces back which adds diff noise to the bumpversion commit.