How can I add remote repositories in Mercurial?
Asked Answered
D

4

107

I am working with Git repositories in the following way:

  • I have the master repository and several remotes on the different production machines.
  • I am pushing the production code to the remotes and restart the services for the changes to take effect.

I am about to switch from Git to Mercurial and I would like to know ahead how I can achieve something like that.

Dismember answered 10/2, 2011 at 11:13 Comment(0)
S
137

You add entries to the [paths] section of your local clone's .hg/hgrc file. Here's an example of a section that would go in the .hg/hgrc file:

[paths]
remote1 = http://path/to/remote1
remote2 = http://path/to/remote2

You can then use commands like hg push remote1 to send changesets to that repo. If you want that remote repo to update is working directory you'd need to put a changegroup hook in place at that remote location that does an update. That would look something like:

[hooks]
changegroup = hg update 2>&1 > /dev/null && path/to/script/restart-server.sh

Not everyone is a big fan of having remote repos automatically update their working directories on push, and it's certainly not the default.

Sheffield answered 10/2, 2011 at 15:42 Comment(6)
For anyone just wanting to see the remotes use hg paths which is equivalent for git remote -v.Hupp
default-push (instead of for example remote1) enables one to just type "hg push". The default-push repository is then used. Very helpful.Dearborn
@Dearborn default-push is only necessary/useful if your usual push target differs from your usual pull source. If they're the same (or you never pull) then default suffices.Sheffield
Just to add even more about this: if you have both default-push and default in your config file, then the first will be used to push and the latter to pull. If you want to push and pull from the same remote repo (which you probably do if you're using Mercurial in a centralized-like way), then only put default in the file. It would be so cool if they added a little command line option to just do that on first push... (or maybe I'm too much of a CVS person ;-))Mahout
I have Mercurial v2.6.2 installed on my Mac, and the file to set the paths is in .hg/hgrc (no DOT before the file name).Ordinarily
you can also put it in mercurial.ini file and it will workAlyosha
I
10

if you want to add default path, you have to work with default in your ~project/.hg/hgrc file. As Follows:

[paths]
default = https://path/to/your/repo

Good Luck.

Illusionary answered 23/8, 2016 at 9:16 Comment(0)
W
5

You could have a look at hg-git GitHub plugin:

hg-git general idea

adding the ability to push to and pull from a Git server repository from Mercurial. This means you can collaborate on Git based projects from Mercurial, or use a Git server as a collaboration point for a team with developers using both Git and Mercurial.

Note: I haven't tested that tool with the latest versions of Mercurial.

Woodhouse answered 10/2, 2011 at 11:56 Comment(2)
I have the ability to port everything to mercurial, I would like to use only one tool for my source management. Convert once the repository build the appropriate structures and then only mercurial commands for production. I am kind of aware that both git and mercurial can collaborate but never tried it.Dismember
^Chris: so is your question: how do I convert Git repos to Mercurial ones?", or "how to declare/setup remote Hg repo?" ( like in superuser.com/questions/43686/…), or "where a remote is declared in Hg?" (crazythinking.wordpress.com/2009/03/07/…)Woodhouse
M
0

If you're on Unix and you have Git installed, you can use this bash function to readily add a path to the remotes without a text editor:

add-hg-path() {
    git config -f $(hg root)/.hg/hgrc --add paths.$1 $2
    awk '{$1=$1}1' $(hg root)/.hg/hgrc > /tmp/hgrc.tmp
    mv /tmp/hgrc.tmp $(hg root)/.hg/hgrc
}

Then invoke it with:

$ add-hg-path remote1 https://path.to/remote1

If someone would like to build a Powershell equivalent, I'd like to include that as well. Other potentials improvements include error checking on the parameters and factoring out the call to $(hg root).

Mediacy answered 19/8, 2016 at 16:19 Comment(2)
why are you running the git command to deal with hg stuff?Gratuity
Because unlike Mercurial, git provides a tool for modifying config, and at least in this case, the syntax is compatible. If I'd been aware of another tool that did the job and was more generic, I'd have used that.Mediacy

© 2022 - 2024 — McMap. All rights reserved.