Reputation: 48853
Currently in my practice I use VERSION file to store:
major=2 minor=0 fix=1
which mean that sources for product version v2.0.1 or newer.
Before each release I must commit update to this file so tag with name tag2.0.1 or release-2.0.1 cover above content (and not previous version!).
I think that it is possible to avoid this job by automatically generating VERSION file from build script.
Look to rev history:
+--+-----+----------------------+-YY--+----+------+------+-HH--> dev| | ^ ^ | | | | | | | | | | | v v v | | | | | | +--+------+-ZZ---+--> | | | | | | b2 | | | | | | | | | v v v | | | | | | t2.0.0 t2.0.1 t2.1.0 v v | | v v t0.1.0 +---+--XX--+-+---+-+-----+------+------+------+------+---> b1 | | | | | | | | v v v v v v v v t1.0.0 t1.0.1 t1.0.2 t1.1.0 t1.2.0 t1.2.1 t1.2.2 t1.2.3
At point XX version is 1.0.0, at point YY version is 1.0.2, at point ZZ version is 2.0.1.
For point HH is don't know how set version. I think it must be 1.0.2, because we does not merge dev branch with release branch b2.
I read:
$ hg help revsets
but don't see how can I find nearest tag to given revision. With Git and Bzr I have less experience...
Or if this s not possible I look for arguments. Also I like to hear how avoid manually maintain VERSION file if this possible (or arguments why this is not possible).
PS. VERSION file needed to maintain package dependency and to identify product source state in feedback from users.
PSS. nearest tag to given revision term can look something fuzzy but every developer can say on which version of product it works. Why this can not do machine?
Upvotes: 2
Views: 1051
Reputation: 5505
bzr tags --sort=time | tail -n1 | cut -d ' ' -f1
Adapted from dOxxx's answer. I saw that the tags are normally sorted by name, but it can be sorted by time with an argument.
You can even make an external bzr alias using the extcommand plugin.
bzr branch http://bzr.oxygene.sk/bzr-plugins/extcommand/ ~/.bazaar/plugins
Then you can add the following to ~/.bazaar/bazaar.conf
[EXTERNAL_ALIASES]
last-tag = bzr tags --sort=time | tail -n1 | cut -d ' ' -f1
Then you can do:
$bzr last-tag
v0.9.0-SNAPSHOT
Upvotes: 3
Reputation: 1539
bzr tags
lists the tags (and their corresponding revisions) in the current branch. I believe the most recent tag is listed first, so you could probably do something like this:
bzr tags | head -n1 | cut -d ' ' -f1
Upvotes: 1
Reputation: 62188
You could use something like this:
hg log --template "{latesttag}-{latesttagdistance}-{node|short}\n" --rev <REV>
Which returns a string like:
2.1.4-2-12eeab7a8073
This tells us that:
Read about templates for more information.
Git
has a built-in describe
command that provides the same information. However, you must understand that by default it only works with annotated tags (see the man page for details).
Upvotes: 5
Reputation: 497152
Git has a command that's exactly designed for this: git-describe
. Exactly how to use it depends on your needs, but in general, git describe [opts] <commit>
produces something of the form <tag>-<n-commits>-<short-hash>
, telling you the most recent tag, how many commits have been made since then, and an abbreviated hash of the commit. For example, it could give you v1.7.8-rc0-32-g87bf9a7
.
Relevant options:
--tags
- include all tags, not just annotated tags. You probably want this.--match <pattern>
- include only tags matching the given pattern, so you can limit yourself to version tags and not anything extraneous.--abrev=<n>
- use n
digits of the hash (set to 0 to suppress it)and several more - see the manpage.
With respect to your VERSION file: you should generally not track it. Having to commit modifications to it is self-defeating; the commit contains the file, and so the version is (slightly) changed when you modify it and commit it. Instead, you can auto-generate it as part of your build/deployment process, and include it in source distributions as well. You can look to Git's source for a nice example of this - there's a script called GIT-VERSION-GEN which is invoked by the Makefile, and is essentially a light wrapper around git-describe. It creates a version file, which is then packaged up into source tarballs, and whose contents are used by the rest of the build process to bake the version number in during compilation.
Upvotes: 2
Reputation: 46444
Have you looked at git describe
for git? It will show the most recent tag that is reachable from a commit.
Upvotes: 2