Push to multiple remote repositories from a single local repo in Mercurial
Asked Answered
C

2

29

I was considering using AppHarbor to host a lightweight website and was investigating their Mercurial integration.

Currently I use Kiln for my remote repositories, but currently AppHarbor only supports BitBucket integration.

Is it possible to have 2 remote repositories for a single local repository? So when I push commits from my local, they both get the push?

I don't ever want to pull from BitBucket, only push so that it can then be grabbed by AppHarbor and deployed.

Contactor answered 3/6, 2011 at 4:44 Comment(0)
D
45

You can set multiple remote repository aliases in the [paths] section of the repository configuration file. This file is in .hg/hgrc, and you would add paths like this

[paths]
default = http://kilnhg.com/repo
bitbucket = http://bitbucket.org/repo

Then you would run hg push bitbucket to push to bitbucket and hg push to push to kiln, which is also the default here. The alias default is the one that's used when you don't specify anything else. This way push and pull with no arguments would use your preferred remote host, kiln.

Sadly you can't do a hg push * type command to push to all remote hosts at once, you have to specify each push destination one by one.

Dehart answered 3/6, 2011 at 7:20 Comment(3)
fantastic. I'll give it a go and report back!Contactor
looks like winner! The only thing is that file, for windows, was .hg/hgrc rather than .hg/configContactor
Woops, typo/thinko. I was thinking of git's config file.Dehart
D
2

I'm not sure if you can edit the hgrc file on Bitbucket/Kiln. If you can, you may be able to make this automatic. If not, you could push to another local copy, which then pushes to both Bitbucket and Kiln using Hooks. See this answer by Ton (included below for convenience):

In your central server you create an changegroup hook.

So your central server would have the following hgrc:

[paths]
server2=http://server2
server3=http://server3
[hooks]
changegroup.server2 = hg push -f server2
changegroup.server3 = hg push -f server3

You can have multiple hooks for the same event, so that shouldn't be an issue. The advantage of the changegroup hook over the changeset hook is that it is run far less often.

Damon answered 4/6, 2011 at 11:58 Comment(3)
an anonymous user proposed a change to your post. It is hard to tell if it is valid, could you take a look?Aristotle
Oops, apologies, I didn't get any notification of it. I checked the docs (mercurial.selenic.com/wiki/Hook) and they say for multiple you should use a suffix, so the edit looked good (and has been approved) :-)Damon
you don't get any notification :) I just thought it would be easier to ask you personally :)Aristotle

© 2022 - 2024 — McMap. All rights reserved.