Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the tag changeset after you clone or pull to a tag using mercurial?

As the definite guide aptly points out (search for "Tags and cloning"):

When you run hg clone -r foo to clone a repository as of tag foo, the new clone will not contain any revision newer than the one the tag refers to, including the revision where the tag was created. The result is that you'll get exactly the right subset of the project's history in the new repository, but not the tag you might have expected.

It means hg tags in your new clone does NOT show the foo tag. Same thing happens if you had cloned before foo tag was added, and you do hg pull -r foo.

(Digression: tag is about the only thing I don't quite get in hg. I understand there are advantages (e.g. merge) in putting it in a changeset, but it always feels weird to have meta data mixed with source code.)

It should be obvious that I'm asking for an automated way, instead of pulling the tag changeset as a separate manual step.

I know I could check for this scenario in an incoming hook (so it works for both clone and pull), or wrap clone and pull.

But is there a better/easier way?


UPDATE hg bug tracker already has this issue.

like image 440
Geoffrey Zheng Avatar asked Sep 22 '10 15:09

Geoffrey Zheng


People also ask

How do you tag in Mercurial?

You can use "hg tag" command with an option -l or --local. This will store the tag in the file . hg/localtags, which will not be distributed or versioned.

What is Mercurial changeset?

A changeset (sometimes abbreviated "cset") is an atomic collection of changes to files in a repository. It contains all recorded local modification that lead to a new revision of the repository. A changeset is identified uniquely by a changeset ID. In a single repository, you can identify it using a revision number.

How do you remove a tag on Mercurial?

If you want to remove a tag that you no longer want, use hg tag --remove . You can also modify a tag at any time, so that it identifies a different revision, by simply issuing a new hg tag command.


1 Answers

You want a giant hack with bash and an embedded Perl script? Well, here it is...

#!/bin/bash
if [[ "$1" == "" || "$2" == "" || "$3" == "" ]]; then
  echo 'hgclonetag <src> <tgt> <tag>'
  exit 1;
fi

REV=`hg log -R $1 --rev $3: --limit=2 | perl -F: -lane 'if (/:([\dA-Fa-f]+)$/) {print $F[2] if defined($flag);$flag=1;}'`
hg clone --rev $REV $1 $2

This invokes the hg log command to extract the revision number after the first tag-related revision and then clones to this revision.

Currently this does not work on remote repos: -R switch only works on local repos unfortunately.

like image 190
Richard Cook Avatar answered Sep 28 '22 05:09

Richard Cook