mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
321 stars 23 forks source link

How to undo the version string into a VCS ref? #20

Closed yajo closed 3 years ago

yajo commented 3 years ago

So I'm in a repo and I do this:

❯ dunamai from git --style pep440
3.0.0.post3.dev0+d929b5a

Cool!

However, would there be any way to obtain the VCS ref that I can checkout based on that version? Like a to command:

❯ dunamai to git --style pep440 3.0.0.post3.dev0+d929b5a .
v3.0.0-3-gd929b5a

That ref is something git understands and that I can pass to git checkout. Actually you can use git to get it:

❯ git describe --tags --always HEAD
v3.0.0-3-gd929b5a

Note: this example is obtained while using this repo and commit, in case it helps: https://github.com/Tecnativa/doodba-copier-template/commit/d929b5a4edccb8bc46552229553aad84a41b6bda

pawamoy commented 3 years ago

Curious: how come does git ouputs a v prefix on your side?

% git describe --tags --always HEAD
0.10.4-10-gbe3849d

EDIT: ah, it's obviously because your latest tag is v3.0.0 and mine is 0.10.4.

mtkennerly commented 3 years ago

Since your version format includes the commit hash, you could do this:

$ echo 3.0.0.post3.dev0+d929b5a | awk -F+ '{print $NF}'
d929b5a

$ echo 3.0.1 | awk -F+ '{print $NF}'
3.0.1

Because of the ability to set a custom --pattern and --format, it would be hard for a to command to work generically. But using the above, you would just need some custom logic to say, if there's no + in the input, then adjust the output so it matches your tag pattern (e.g., add a v prefix).

yajo commented 3 years ago

Hmm I see. I was expecting to use this lib to somehow be able to undo that, but indeed it's technically quite difficult.

Just the v stuff in itself is a problem. Git is able to let you tag v1.0 and 1.0 separately on different commits, because a tag is just a string for git, but that'd be probably confusing dunamai.

Well, in any case now I know how to proceed to fix my problem. Thanks everybody!