Search code examples
mercurial

Mercurial - how to make a local central repository


I would like to have a central repository in a directory on my local computer without setting up a server.

Context: I am working with my boss on a local server inside our LAN. We both are using a vnc connection onto the server, and are doing our work there for simplicity reasons. I would like to set it up so that I can have a copy of my scripts for development, and then when I get to a release, I will push it to a different directory that my boss can then run them from (or even better pull from to his own set and run from there).

I read that you can create a hg server by running 'hg serve', but I do not want to open it up to the LAN, because I don't want it to be accessible.

I tried running 'hg push /home/source' and it gave me an error. I then ran 'hg init' while in that directory and tried again. It looked like it worked, and then didn't show any files in the directory. I ran status and it showed nothing, and then ran log and it showed the commits.


Solution

  • ... without setting up a server

    One way I've used to share a "central" Mercurial repository without having to deal with any "server" issues is to have the "central" repository in a folder on Dropbox.

    For example, suppose:

    1. your repository is named "repo" and that your "private" copy is in ~/repo
    2. your Dropbox directory on your computer is ~/Dropbox/

    Then:

    cd ~/Dropbox
    hg clone ~/repo
    

    Now suppose you make some changes in ~/repo. You can then "push" them from ~/repo to ~/Dropbox/repo, or (more easily, as explained below) "pull" them into ~/Dropbox/repo when you're ready.

    To make updating the "central" repository convenient, you might like to create a script such as:

    #!/bin/bash
    cd ~/Dropbox/repo
    hg tip
    hg pull -u
    hg tip
    

    Notice that in the script, there is no need to specify the source from which to pull; the hgrc file that's created when you created the clone keeps track of that. (Thank you, hg.)

    If your colleague has direct access to a folder on your computer, then you could still adopt the strategy described above, without using Dropbox.

    Needless to say, there are many variations.

    Needless to say also, if more than one person attempts to commit changes to the shared folder, chaos can easily ensue.