106

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.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
topless
  • 8,069
  • 11
  • 57
  • 86

4 Answers4

136

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.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 24
    For anyone just wanting to see the remotes use `hg paths` which is equivalent for `git remote -v`. – Benbob May 26 '11 at 22:24
  • 5
    default-push (instead of for example remote1) enables one to just type "hg push". The default-push repository is then used. Very helpful. – Christian Jun 09 '12 at 18:13
  • 6
    @Christian `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. – Ry4an Brase Jun 10 '12 at 00:18
  • 2
    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 ;-)) – tiktak Jan 17 '13 at 19:41
  • 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). – Regis Zaleman Oct 28 '13 at 17:34
  • you can also put it in mercurial.ini file and it will work – DPM Aug 04 '17 at 15:47
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.

Aakash
  • 21,375
  • 7
  • 100
  • 81
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.

Cezary Drożak
  • 326
  • 4
  • 11
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    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. – topless Feb 10 '11 at 12:39
  • 2
    ^Chris: so is your question: how do I convert Git repos to Mercurial ones?", or "how to declare/setup remote Hg repo?" ( like in http://superuser.com/questions/43686/setting-up-a-remote-mercurial-repository), or "where a remote is declared in Hg?" (http://crazythinking.wordpress.com/2009/03/07/starting-a-mercurial-hg-remote-repository/) – VonC Feb 10 '11 at 12:45
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).

Jason R. Coombs
  • 41,115
  • 10
  • 83
  • 93
  • why are you running the `git` command to deal with hg stuff? – Michael May 21 '23 at 21:57
  • 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. – Jason R. Coombs May 23 '23 at 17:11