开发者

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

I am just playing around with Mercurial at the moment and this may never come up as an issue, but I just created a repository and added some changes. I tagged it at one point then created a named branch at another. Both the tag and the branch have the same name. If I do hg update name it switches to the tagged version. Is there any way to switch to the branch other than by using a revision number on the branch?

I think what made me think about this was that if we were to write some scripts for automatically buildi开发者_如何学Gong a particular revision we would want to just specify either a tag or a branch to build from. If someone happened to use the same name in a tag and a branch then we would run into problems with the script getting the correct revisions. Is the only solution to this to make sure that they are unique, e.g. by pre-pending branch or tag to the name?


You get the tip revision of the branch by parsing the output of hg branches.

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

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

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

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

Getting the tag revision works similar, using hg tags.

Now your script is able to update to the branch/tag in question.


I think you could do it with:

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

which uses the revsets feature (see hg help revsets in a newer Mercurial).

But were it me I'd just delete the tag after beating the person who created it about the head and neck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜