2

I would like to activate a bookmark that is on the revision if I update to that revision. For instance, if I do this

hg up -r "bookmark('re:fix.+2572')"

This will update me to the revision the bookmark points to, but it won't activate the bookmark.

Documentation says:

Note that updating to a revision that has a bookmark without using the bookmark name will not activate the bookmark (e.g. if the feature bookmark points to revision #20 and you do hg update --rev 20 the feature bookmark will not be activated).

But to me it seems like a very nice feature/option to have. More so this works if in TortoiseHg UI, but I couldn't figure out how to do it in the command line version of Mercurial.

Is there a way/workaround to do it ?

EvgeniySharapov
  • 3,078
  • 3
  • 27
  • 38
  • Get full name of bookmark before `hg up`? – Lazy Badger Oct 23 '15 at 03:18
  • Well, yes. However what I want is if a revision has just one bookmark, then activate that bookmark if I update to that revision. Bookmark names can be surprisingly long. – EvgeniySharapov Oct 23 '15 at 03:30
  • Don't want *strange* - `hg up -r REV` and `hg up BOOK` behaves differently and it is good and right - I want activate boomark only when I want. Bookmark name is long - okay, don't use fu** looong names (change idiotic policy) or: *use brain* something like `hg up 'hg log -r "bookmark('re:fix.+2572')" -T "{bookmarks}"'` – Lazy Badger Oct 23 '15 at 04:15
  • Well, i have to work with multiple teams and developers 99% of whom use git (not that it matters). Enforcing short branches/bookmarks seems much harder task to accomplish than even writing an extension to Mercurial. So I guess the problem could be stated different. Mercurial has `revsets` which I like, I would like some of that functionality be applied to finding bookmark names. I have a ZSH function that helps me to tab-complete name of the bookmark on Linux box, but on Windows I am out of luck. – EvgeniySharapov Oct 24 '15 at 17:27
  • On Windows you'll not be able to use planetmaker's alias also - you have to rewrite it into bat-style – Lazy Badger Oct 24 '15 at 17:55

1 Answers1

2

you can create an alias for a new command, let's call it bupdate. Add to your .hgrc:

[alias]
bupdate = !HG up $($HG log $@ -T'{bookmarks}\n' | cut -d\  -f1)

Call hg bupdate like you usually would call hg update. This will activate the first bookmark attached to a specific revision. It will simply update to the revision if there is no bookmark. Updates to the 2nd or 3rd or further bookmarks attached to a revision still need to be done manually.

planetmaker
  • 5,884
  • 3
  • 28
  • 37
  • *Regexp* (cset hash|number is unknown, btw) can return more than one revision in set... you'll fail in this case – Lazy Badger Oct 24 '15 at 10:50
  • True. However I don't think that it's a big issue. A 'normal' update would also fail if I give it non-unique revision. – planetmaker Oct 24 '15 at 11:00