I'm using bump2version python module to increment my python codebase version automatically. When the pre-commit hook runs after the commit, the version.sh goes into indefinite loop and version keeps on incrementing in init.py. Did I miss anything
.bumpversion.cfg
[bumpversion]
current_version = 0.0.0
commit = True
message = "Merge the new version"
[bumpversion:file:__init__.py]
.pre-commit-config.yaml
repos:
- repo : local
hooks:
- id: VersionIncrement
name: VersionIncrement
entry: ./version.sh
language: script
exclude: (.pre-commit-config.yaml)|(.git/)
version.sh
#!/usr/bin/env bash
git_branch_name=`git branch --show-current`
echo $git_branch_name
if [[ $git_branch_name =~ "feature/" ]]; then
bump2version --allow-dirty --verbose patch
exit 0
elif [[ $git_branch_name == "dev" ]]; then
bump2version --allow-dirty --verbose minor
exit 0
elif [[ $git_branch_name == "master" ]]; then
bump2version --allow-dirty --verbose major
exit 0
else
echo "branch does not exist"
exit 1
fi
if
bump2versionis making a commit, yes you'll get an infinite commit with your setupI would not recommend automatically bumping a version like you're doing (if you really want to increment some number after every commit, consider using
git describewhich does this automatically without having to change your committed code). bothgitandpre-commitare not designed to do what you're doing.if you really want to continue with what you're doing you can skip the infinite recursion by doing something like:
which will utilize SKIP= to bypass itself
or you can use
bump2version's--dry-runwhich may be more appropriatethat said, I really don't expect making a commit to work while you're making a commit -- and will probably break
gitor your history in mysterious ways (especially when coupled withgit commit -aor such)disclaimer: I wrote pre-commit