I have a git repository which uses a submodule which I’d like to point at an annotated tag, but when I do git submodule update new tags don’t get fetched. I can get new tags in the submodule by cd-ing into the submodule and doing a git fetch --tags there, but I’d really like to do all of this from the outside as it’s scripted.
I can’t find anything in the git documentation suggesting a way to get git submodule update to include tags (my git version is 1.7.3.5).
Obviously there is another possibility – to point the submodule at the commit which the tag points to rather than the tag itself, but this doesn’t seem as neat.
Is there a way of getting git submodule update to include tags?
git submoduleis implemented as a shell script, so it’s easy to see what it’s doing — it might be at/usr/lib/git-core/git-submoduleif you’re using a packaged version. Essentially it just runsgit-fetchin the submodule if it the object name (SHA1sum) stored in the main project’s tree doesn’t match the version checked out in the submodule, as Koraktor points out.The documentation for
git fetch(orman git-fetchwhile kernel.org is down) says that it should fetch every tag that points to a downloaded object, and the downloaded objects will include every commit that’s an ancestor of every branch that’s fetched. That means it’s surprising to me that you don’t get all the relevant tags on agit submodule update.If it’s the case that what you really want is for your script is to try to set a new submodule version and commit that result, I don’t think that
git submodule updateis the tool that you want – that’s just for making sure that your submodules are at the right version based on what’s currently in the main project’s commit. Instead you should just do something like:(I added an extra
git fetch --tagsjust in case your tag isn’t one that points to a downloaded commit.)Well, the only thing that’s stored in the main project’s tree for the submodule is just the hash of the commit object, so even if there were a command that said “set my submodule to the tag
my-tagin that submodule”, it would end up just storing the hash corresponding to that tag anyway…