To install and run the Mercurial source control system using Unit:

  1. Install Unit with a Python language module.

  2. Next, install Mercurial and configure a repository or choose an existing one.

  3. Unit uses WSGI to run Python apps, so it requires a wrapper script to publish a Mercurial repo. Here, it’s /path/to/hg/ (note the extension); the application callable is the entry point for the app:

    from mercurial.hgweb import hgweb
    # path to a repo or a hgweb config file to serve (see 'hg help hgweb')
    application = hgweb("/path/to/hg/repo/or/config/file")


    This is a very basic script; to elaborate on it, see the Mercurial repo publishing guide.

  4. Set permissions for the application directory to ensure Unit can access it, for example:

    # chown -R hg_user:hg_group /path/to/hg/  # user:group for app config in Unit
  5. Finally, prepare and upload the app configuration to Unit (note the use of path):

        "listeners": {
            "*:80": {
                "pass": "applications/hg"
        "applications": {
            "hg": {
                "type": "python",
                "path": "/path/to/hg/",
                "user": "hg_user",
                "module": "hgweb"

    Assuming the config above is saved as hg.json:

    # curl -X PUT --data-binary @hg.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config
  6. After a successful update, you can proceed to work with your Mercurial repository as usual:

    $ hg config --edit
    $ hg clone http://localhost/ project/
    $ cd project/
    $ touch hg_rocks.txt
    $ hg add
    $ hg commit -m 'Official: Mercurial on Unit rocks!'
    $ hg push
    Mercurial on Unit - Changeset Screen