How to change the default branch to push in mercurial?
Asked Answered
F

3

9

I like creating named branches in Mercurial to deal with features that might take a while to code, so when I push I do a hg push -r default to ensure I'm only pushing changes to the default branch. However, it is a pain to have to remember -r default every time I do do a push or outgoing command.

So I tried fix this by adding this config to my ~/.hgrc:

[defaults]
push = push -r default
outgoing = outgoing -r default

The problem is, those config lines are not really defaults, they are aliases. They work as intended until I try to do a hg push -r <some revision>. And the "default" I've setup just obliterates the revision I passed in. (I see that defaults are deprecated, but aliases have the same problem).

I tried looking around, but I can't find anything that will allow me to set a default branch to push AND allow me to override it when necessary. Anyone know of something else I could do?

ps: I do realize that I could have separate clones for each branch, but I would rather not do that. It's annoying to have to switch directories, particularly when you have shared configuration or editor workspaces.

Faubion answered 5/5, 2010 at 23:26 Comment(0)
D
6

I don't think you can do it with pure mercurial, short of having a clone with only that branch in it (which I was was about to suggest until you said it wasn't your cup of tea). If it's really killing you you can create a tiny wrapper script like:

#!/bin/sh
HG=/full/path/to/hg # executable
if echo $* | grep -P -q -- 'push.*\s-r($|\s)' ; then
   $HG $*
else
   $HG $* -r default
fi

name it 'hg' and put it earlier in your path.

Darksome answered 5/5, 2010 at 23:46 Comment(1)
I had to modify the script some to make it not add "-r default" to commands other than push and outgoing, but thanks very much for the push in the right direction.Faubion
N
1

Are you using Tortoise HG perhaps? Doing a full revert to an explicit branch name will cause Tortoise HG to remember the branch you're working on during subsequent commits. I'm not sure what metadata it gleans this from.

hg up -r {branchname}

e.g.

hg up -r dev 
Norvil answered 14/1, 2011 at 20:31 Comment(0)
C
0

Since normally you should push changesets in the current branch you are working, I modified the above answer made by ry4an-brase, to push current branch with a notice.

#!/bin/sh
HG=/usr/bin/hg # executable

if echo $* | grep -P -q -- 'push\s*$' ; then
    printf "\033[1;31mChanged to: hg push -r .\033[0m\n"
    $HG $* -r .
else
    $HG $*
fi
Cinderellacindi answered 28/5, 2020 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.