The vc bundle is a neat little package that extracts information about a git repo for easy insertion into a LaTeX document. It doesn't currently extract information about whether the current commit is tagged and what the tag name is. How would I edit the vc script to do this?

And then how would I edit the vc-git.awk script to add an extra line to the generated vc.tex file? Presumably I want a line that looks like:

print "\\gdef\\GITTag{" Tag "}%"

but I need an earlier line that tells awk what " Tag " means?

This isn't a question about LaTeX, it is about git, awk and bash...

git log --decorate -1 [commit]

If commit (HEAD if omitted) has tags, the commit hash will be followed by (tag: name) (and possibly multiple other symbolic references too). You can pick this out more specifically with

git log --pretty=%d
  • This i great, I've added Tag: %d to the vc script linked to above, and copied a line in the awk script that extracts the information to a TeX macro. This gives me a macro that does: (HEAD, tag: v1.01, master) I just need to cut this down to the v1.01 part only... – Seamus Jan 11 '11 at 16:30
  • /^GITTag:/ {print $4}' prints v1.01, Now I just need to delete that comma! – Seamus Jan 11 '11 at 20:14
  • print substr($4,1,length($4)-1) works – Seamus Jan 11 '11 at 22:22

You can get what commit tag points to by:

git show -s 'TAG_NAME^{commit}' --format='%H'

Unfortunatly I'm afraid that the only way of checking if commit is tagged it to check all tags.

  • That's the opposite of what I want: I want to know how to know what tag is attached to a given commit... – Seamus Dec 21 '10 at 15:31
  • I don't think the reverse is possible in other way then going through all tags and checking what commits they point to. – Maciej Piechotka Dec 21 '10 at 15:52

You can get from a commit to a tag name by using name-rev.

git name-rev <commit> --tags

An example:

$ git name-rev fcfeabe --tags
fcfeabe tags/v2.36-beta2

So to get only the tag:

git name-rev fcfeabe --tags | awk '{sub("tags/", ""); print $2}' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.