(1) git log
is extremely flexible, with lots and lots of options. You might not be able to reproduce the exact output of the three commands above, but you might come close enough to achieve the effect you need.
For example:
$ git log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1
produces the date, SHA-1 and symbolic references (including tags) of the latest (HEAD) commit:
2010-05-20 45bd5e7 (HEAD, origin/master)
After which, presumably, sed
and/or awk
or maybe Maven-native methods can do the fine-tuning/polishing. Note that a particular tag is associated with a particular commit, so if it was three commits prior to HEAD that was tagged with, for example, "v1.0.0", you are not going to see "v1.0.0" showing up with the above.
(2) A simpler single command to provide a succint description of a commit is:
$ git describe
which writes out the latest applicable tag, the number of commits since the tagged commit, and the SHA1:
v3.3.0-46-g71a77dc
(3) I am not at all familiar with Maven, and have no idea how easy/difficult it is to run external processes, so am unsure whether any of the following help in any way, but I thought I might mention it just in case ...
For the exact purpose that you describe, i.e. tagging builds, in an autoconf/automake framework, I actually use something like:
BUILDTAG="`git symbolic-ref HEAD 2> /dev/null | cut -b 12-`-`git log --pretty=format:\"%h\" -1`"
which produces something suitable for tacking onto the end of a program path:
master-c5282ff
A more extended description, suitable for including as a comment or a printed identifier:
BUILDDESC="$(git symbolic-ref HEAD 2> /dev/null | cut -b 12-)-$(git log --pretty=format:'%h, %ad' -1)"
produces something like:
master-c5282ff, Fri Mar 12 22:19:51 2010 -0600
I think playing around with git log
, possibly in conjunction with text processing tools/methods will get you what you want.