Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all tags in a certain Mercurial branch?

Tags:

mercurial

Is it possible to list the tags only on a certain branch? (from command line preferably)

For example:

$ hg branch test1
... (make some commits)
$ hg tag mytag_on_test1_branch

$ hg branch test2
... (make some commits)
$ hg tag mytag_on_test2_branch
... (make some commits)
$ hg tag mytag_on_test2_branch_2

Now hg tags returns:

$ hg tags
tip                                5:34603c3a4107
mytag_on_test2_branch_2            4:72db17d2170c
mytag_on_test2_branch              2:09aed50d8b95
mytag_on_test1_branch              0:d43c48c0e1d8

I would only like to see tags on branch "test2", like this:

mytag_on_test2_branch_2            4:72db17d2170c
mytag_on_test2_branch              2:09aed50d8b95

Is this possible?

like image 232
johndodo Avatar asked Sep 17 '15 06:09

johndodo


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.

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.

How do I switch between branches in Mercurial?

Quickly switch to another branch or bookmarkIn the Status bar, click the Mercurial Branch widget to open the Branches popup. Select the branch or bookmark to which you want to switch and in the menu that opens, click Update.


1 Answers

Like so often, the answer lies in the proper use of revsets; they are a powerful tool to limit the revision ranges to nearly whatever need. See hg help revsets for details.

In your case we also make use of the output templating to only get shown the tags instead of full log output of those revisions. Thus if you need all tags for THISBRANCH:

hg log --rev="branch(THISBRANCH) and tag()" --template="{tags}\n"

Sample output for widely-tagged repo

hgsubversion>hg log -r "branch(stable) and tag()" -T "{tags}\n"
1.5.1
1.6.1
1.6.2
1.6.3
1.7
1.8
1.8.1
1.8.2
like image 194
planetmaker Avatar answered Oct 21 '22 10:10

planetmaker