Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to the current bookmark in mercurial

I am using bookmarks in mercurial to emulate a git branches-like workflow.

One thing I'm finding is that whenever I push, I invariably want to push just the current bookmark. Rather than typing

hg push -B <bookmark_name>

all the time, I'd like to alias hg push to just push the current bookmark. To do that, I need a way of referring to the current bookmark without mentioning its name. Is there a way to do that?

like image 383
HighCommander4 Avatar asked Sep 12 '13 17:09

HighCommander4


3 Answers

I understand it was asked two years ago, but I found this page in Google and none of the answers helped. So here's what did the trick for me (Linux):

[alias]
currentbranch = !cd `$HG root` && cat .hg/bookmarks.current
pushb = !$HG push -B `$HG currentbranch`

cd is required for this to work from non-root directories.

like image 160
Alexander Sukhoverkhov Avatar answered Oct 18 '22 08:10

Alexander Sukhoverkhov


Current bookmark name stored in .hg/bookmarks.current file of your repository. As an alias you can use something like this:

pushb = push -B `cat .hg/bookmarks.current`

Also note that when you update you repository state to any other revision, there won't be file .hg/bookmarks.current.

like image 34
rpeshkov Avatar answered Oct 18 '22 08:10

rpeshkov


OK, platform independent solution, somehow ugly

pushb = push -B `hg log --template "{bookmarks}\n" -r "bookmark() & ."`

or, with nested command in more natural way it must be: hg parents --template="{bookmarks}\n"

Ugly because pure Mercurial-way using nested shell-aliases in hgrc

[alias]
cb = !$HG log --template "{bookmarks}\n" -r "bookmark() & ."
pushb = push -B cb

does not work for me

>hg pushb
...
bookmark cb does not exist on the local or remote repository!

Edit

Long time later, with new solution. According to hg help push

If -B/--bookmark is used, the specified bookmarked revision, its ancestors, and the bookmark will be pushed to the remote repository. Specifying "." is equivalent to specifying the active bookmark's name.

if order to "push the current bookmark" you can use just

hg push -B .

like image 45
Lazy Badger Avatar answered Oct 18 '22 09:10

Lazy Badger