tbump
tbump copied to clipboard
Make tbump VCS agnostic - `--only-patch` if no `.git` folder exists
Hello there,
Today is a day when I discovered bumpversion. I got excited, I played a bit with it (and my org crazy versioning convention).
Then... I came across https://hackernoon.com/lets-automate-version-number-updates-not-a91q3x7n and... I got charmed! Thanks for that history and for this tool. I am really interested in using it, but...
It seems it's a bit git default depended. I cannot run it without .git in my repo:
:: Bumping from 2020.05 to 2020.06
Error: Command `git status --porcelain` failed
Then I learned about --patch-only, perfect! But why default to git if a repo is no git repo at all? Of course, too smart/implicit tools is not an answer always, but that's the behavior of bumpversion I really liked.
Bumping a version is VCS agnostic operation, right?
I would like to avoid using --only-patch option each time if that's possible. I can't see if I can use a config for it though... (like pytest addopts or so).
As I don't use git for this projects, I wanted also to remove [git] key in config, but it seems required.
Please let me know what you think!
If you only want to bump the files without performing any git actions or running the hook commands, use the --only-patch option.
Someone might still want to use hooks while not using git. But hooks are git related, not pre-patch and post-patch of tbump itself, right?
Someone might still want to use hooks while not using git.
Wellt, let's take an example:
# in tbump.toml
# <- this is a tbump hook
[[before_commit]]
name = "do foo"
command = "do-foo"
# in .git/hooks/pre-commit
# <- this is a git hook
do-bar
Here do-bar will run whether or not you are using tbump to create a git commit, and do-foo will run any time tbump is called (unless the --only-patch tbump option is used).
Currently there's no way to tell tbump to both patch the files and run the tbump hooks - maybe you can open a different issue for that?
Bumping a version is VCS agnostic operation, right?
Well, not really. In order to do that safely, you need to be able to revert the changes if something goes wrong. That's the reason
why the git status command is run, by the way :)
As I don't use git for this projects
Out of curiosity, do you use a different VCS (like mercurial or svn) - or you just use no VCS at all?
I'm not really sure if tbump should check for a .git folder and "magically" trigger the --only-patch behavior.
I'll take a look at what bumpversion does, because I know it supports several VCS.
Currently there's no way to tell tbump to both patch the files and run the tbump hooks - maybe you can open a different issue for that?
Sure I can :)
Out of curiosity, do you use a different VCS (like mercurial or svn) - or you just use no VCS at all?
Yes, it's Perforce. As for tbump hooks, I could p4 edit files (marks files as editable, normally files in repo are read only), then run tbump, then p4 revert unedited files (that would left only files modified with tbump), then p4 submit with a message (like git push). I was already thinking to just put those in Makefile rule.
I'm not really sure if tbump should check for a .git folder and "magically" trigger the --only-patch behavior.
Having same feeling about magical behavior. Bumpversion just started to work without git after I moved .git folder :)
But if VCS could be abstracted out and just explicitly turned off in config in non git cases... (where git would be on by default).
Let me rephrase.
So as of today, --only-patch means truly only patch. That should remain untouched. But it fixes my problem of not using git, as there is no other solution. While I just don't want to use git integration.
That somehow make me thinking of generic VCS abstracting out, but that means, the hooks also could be handled in a generic way.
If the hooks would be a whole list, like:
- pre run - maybe no input or a repo dir
- pre file edit - each file being an input; I would run p4 edit to let P4 server I am about to edit it, that makes file writable as well
- post file edit - each file being an input
- post run - repo dir as an input + maybe files that were edited; I would p4 submit here to upload changed to a server; git could tag, commit, status, push
... + any other points I have no idea that are needed, then each new VCS integration could just implement handlers for those. I have no idea how git is interleaved currently with this tool, sorry - I am mostly thinking out loud.
I'll take a look at what bumpversion does, because I know it supports several VCS.
It does have some heuristic it seems: https://github.com/c4urself/bump2version/blob/a58e20dbdde646c43c128124d880e772d3817699/bumpversion/cli.py#L227. It runs some test commands to determine type of VCS:
- git: ["git", "rev-parse", "--git-dir"], https://github.com/c4urself/bump2version/blob/a58e20dbdde646c43c128124d880e772d3817699/bumpversion/vcs.py#L62
- mercurial: ["hg", "root"], https://github.com/c4urself/bump2version/blob/a58e20dbdde646c43c128124d880e772d3817699/bumpversion/vcs.py#L143
Which one works first wins :)
Either way Dimitri - it's a really good tool and if covering other VCSes is not a target for it at all, closing this issue would be entirely understandable :).