mercurialhgrc

How do I swap my master repository location in mercurial


I have a local mercurial repository. And I back it up with a clone in a separate folder that lives in my google drive folder. Every now and again I'll go into the google drive repo and do an hg pull, and google drive takes care of backing it up. But I'd like to swap those responsibilities, so that my local is a clone of the one in google drive. In other words, today I do this:

From my local c:\source folder:

  1. do stuff
  2. hg commit
  3. cd c:\googledrive\source
  4. hg pull

I would rather:

From my local c:\source folder:

  1. do stuff
  2. hg commit
  3. hg push

I don't know what to do in my hgrc files to make that happen. Can someone help? Here's the contents of my c:\source hgrc:

# Generated by TortoiseHg settings dialog

[tortoisehg]
summarylen = 80
engmsg = True
editor = notepad
tabwidth = 2
forcerepotab = False
monitorrepo = localonly

[ui]
username = *****

And this is the contents of the clone in google drive

[paths]
default = c:\source\SwissArmyKnife

Solution

  • Your question reveals an illuminating misconception. When one says that Mercurial is a Distributed Version Control System (DVCS), it means that there is no ‘master‘ repository.

    When you type hg push <repo> or hg pull <repo>, then Mercurial compares the changesets in the current repository with those in <repo>, and pushes or pulls changesets to make this one and the remote one consistent. The <repo> can be indicated by a URL (that is, ssh://..., or http://...) or else by a shorthand named in your .hg/hgrc: thus in your case you might add

    [paths]
    gdrive = c:\googledrive\source
    

    and that would mean that you could write hg push gdrive or hg pull gdrive and Mercurial would know what you meant. You can have multiple paths listed here.

    There's one ‘magic’ path, however. If you have a path default then that's the path that Mercurial uses if you don't specify a <repo>.

    Thus (finally), if you adjust the .hg/hgrc in your c:\source folder to include

    [paths]
    default = c:\googledrive\source
    

    then in that directory plain hg push will sync changesets with that drive.

    When you clone a repository (hg clone) Mercurial generally adds to your .hg/hgrc a default = ... which indicates the location from which you cloned the repository. Given that default behaviour, it's very natural to think of that repository as the ‘master’ one, but there's nothing fundamentally special about it.