Mercurial: How to switch to a named branch if the tag has the same name?

I'm just playing with Mercurial at the moment, and this may never occur as a problem, but I just created a repository and added some changes. I tagged it at some point, and then created a named branch in another. Both the tag and the branch have the same name. If I do an hg update name , it will switch to the tagged version. Is there any way to switch to a branch other than using the revision number on the branch?

I think that made me think that if we wrote some scripts to automatically create a specific version, we would just want to specify either a tag or a branch for assembly. If someone used the same name in the tag and branch, we would run into problems with the script getting the correct changes. This is the only solution for this to make sure they are unique, for example. by a pre-installed branch or tag to a name?

+6
version-control branch dvcs repository mercurial
source share
2 answers

You get a branch revision by analyzing the output of hg branches .

Consider this situation (a branch and a tag, both called popular ):

 $ hg tags tip 3:afb4026bfe32 popular 1:cea974d8cfc4 $ hg branches default 3:afb4026bfe32 popular 2:aa7ede2bb3f6 

In bash-like shells, you get a revision of the popular branch branch with:

 $ hg branches | grep popular | awk -F ':' '{print $2}' 

Getting a tag check is similar using hg tags .

Now your script will be able to update the corresponding branch / tag.

+3
source share

I think you could do this with:

 hg update -r "limit(heads(branch(name)),1)" 

which uses the revsets function (see hg help revsets in the new Mercurial).

But be it me, I will simply remove the tag after beating the person who created it around the head and neck.

+2
source share

All Articles