callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
303 stars 19 forks source link

bump-my-version does not fail if script hooks fail #236

Open ivan94fi opened 4 days ago

ivan94fi commented 4 days ago

Description

When a command in a pre or post commit hook fails, I expect the bump to fail as well, but this does not happen.

This is because the errors on subprocess.run calls are not handled, but simply logged and ignored. See the 0.26.1 tag version of the run_hooks() function: https://github.com/callowayproject/bump-my-version/blob/683904a587a37305e42a29af9c53f27c8f369550/bumpversion/hooks.py#L92-L106

What I Did

Running bump-my-version with the following config:

[tool.bumpversion]
current_version = "0.1.3"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = false
sign_tags = false
tag_name = "v{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = true
message = "Bump version: {current_version} → {new_version}"
commit_args = ""
pre_commit_hooks = ["exit 1"]
post_commit_hooks = ["exit 2"]

Is there any chance that this feature would be implemented? Thank you

coordt commented 1 day ago

A couple of caveats.

I can stop everything on pre-commit hooks, but not on post-commit hooks. The bump will already have happened and be committed and tagged (if configured that way).

Stopping will also leave the repo in an unknown state since bump-my-version has no idea what happens in the hooks.

Any other thoughts about this with that caveat in mind? Any configuration or other things I should keep in mind?

ivan94fi commented 15 hours ago

I can stop everything on pre-commit hooks, but not on post-commit hooks

Yes, this makes sense, the stopping behavior should only happen in setup and pre hooks. In post-commit hooks it would great if we could see a warning message instead of logging at debug level, so that the message would be visible by default.

Stopping will also leave the repo in an unknown state since bump-my-version has no idea what happens in the hooks

That is true, and it is not bump-my-version's responsibility to predict what could be done in those hooks. I think the right way to proceed is to just revert the edits to the files modified by bump-my-version up to that point. For everything else it should be documented that it is the hook creator's responsibility to clean up.

As for the rest, nothing else comes to my mind at this moment.

Thank you for your work, I will be happy to provide feedback and discuss other issues.

coordt commented 9 hours ago

Good points.

I'll schedule this for this weekend (September 28-29).