Trying to get Mercurial on my Raspberry Pi to be a remote repository

The fix for this is in the bottom part of the post, in the last block with the grey background.

I'm trying to get my Raspberry Pi - which is running the stock version of Debian to be a remote repository for Mercurial. I have set up local repositories on my desktop and laptop (running Mageia) and they work fine locally. I want to be able to push and pull any changes to the Pi. I've set-up OpenVPN on the Pi, so I can access it and, hopefully, push and pull my software from anywhere in the world.

So, I have followed these instructions:

Step-by-step (using Apache2 as my web server) and when I try to connect as in step 9.1.2 with this:

Check if it works by directing your browser to yourhost/hg/.

By putting pi/hg into Firefox, I get an internal server error. (Just putting pi into Firefox gives me the default Apache message and all is good.)

My Apache error log shows me this:

Traceback (most recent call last):
  File "/var/hg/hgwebdir.cgi", line 18, in <module>
    application = hgweb(config)
  File "/usr/lib/python2.7/dist-packages/mercurial/hgweb/__init__.py", line 27, in hgweb
    return hgweb_mod.hgweb(config, name=name, baseui=baseui)
  File "/usr/lib/python2.7/dist-packages/mercurial/hgweb/hgweb_mod.py", line 34, in __init__
    self.repo = hg.repository(u, repo)
  File "/usr/lib/python2.7/dist-packages/mercurial/hg.py", line 93, in repository
    repo = _peerlookup(path).instance(ui, path, create)
  File "/usr/lib/python2.7/dist-packages/mercurial/localrepo.py", line 2350, in instance
    return localrepository(ui, util.urllocalpath(path), create)
  File "/usr/lib/python2.7/dist-packages/mercurial/localrepo.py", line 79, in __init__
    raise error.RepoError(_("repository %s not found") % path)
mercurial.error.RepoError: repository /var/hg/repos not found
[Wed Jan 22 17:23:26 2014] [error] [client 10.8.0.6] Premature end of script headers: hgwebdir.cgi

If I try to connect from Mercurial with remote (http) repository as pi/ I get this in my Apache logs:

     [error] [client 10.8.0.6] File does not exist: /var/www/.hg

        In my Tortoise HG logs on the local machine I get this:

   [command returned code 255 Wed Jan 22 17:24:49 2014]


% hg --repository /path/sqlforms outgoing --quiet --template {node}URL goes here ' does not appear to be an hg repository:
    ---%<--- (text/html)enter code here
    <html><body>
    <p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet. Rob     has        changed summat</p>

If I use pi/hg as the remote server, Tortoise HG gives me this:

[command returned code 255 Wed Jan 22 17:25:15 2014]

% hg --repository /path/sqlforms outgoing --quiet --template {node}^M http://pi/hg/
HTTP Error: 500 (Internal Server Error)

[command returned code 255 Wed Jan 22 17:25:24 2014]
sqlforms% 

/var/hg/repos does exist as a directory.

Hopefully I've given the right amount of info there. I'm no Linux newb, but I am to Apache and fairly new to Mercurial, so I'm probably doing something stupid. AFAIK I have faithfully copied the steps on the web site link I showed above. Is that enough information to troubleshoot? If not, I can supply anything else as needed. Many thanks.


It ended up being a number of different things - some of which Mata mentioned, so I'm putting his/her answer down as he/she was kind enough to point me in the right direction. I'm putting some more details below in case it helps someone else because in all documentation I've found some points aren't well made.

    It's important to note that the /var/hg directory that you specify ends up being accessed as server_name/hg when accessing via http. So, if you put a directory on your server in path:

    /var/hg/dex 

    Then this is accessed via http as:

    http://serve_name/hg/dex

    So, in this case the http access you are "mapping" /var/hg/dex as hg/dex

I think what is super-confusing about the documentation is the way hg is used too much and it would be better described if the base directory structure on your server is something like this:

    /var/mercurial_repositories

You would obviously have to set up the Apache config file to point there as its base directory rather than at:

    /var/hg. 

This would make it far more obvious that you are mapping /var/mercurial_repositories to hg when it comes to remote access. The way it is described it is far too ambiguous with hg being used in too many different places. Whereas this might be obvious to experienced users or someone who's had someone sit down and explain it to them, to a newb, it's very confusing. 

Then, the other thing that is not obvious in the documentation is that:

    /var/hg/repos 

is not a directory for ALL repositories. This is a directory for one repository. I struggled with this for quite some time. Again, the documentation is very misleading for a newb. If it said:

    /var/hg/repo (singular) it might be a lot better. 

I realise later, tucked away somewhere in one of the pages of documentation is mentions you need subdirectories within repos, but, again, it is very confusing for someone starting out the way this is worded. Something like:

    /var/mercurial/repositories_base_directory

Would be far clearer.

Also, for every directory you set up in your base directory, you have to have a new entry in the file:

    /var/hg/hgweb.config

This is done like this:

    [paths]
    c82xx = /var/hg/repos/c82xx

The documentation on this is especially terrible the way it just says:

    repos/ = repos/

The issue with these path settings, which, again is explained nowhere (as far as I could see), is that on the left hand side of the equals sign is how your remote machine accesses the directory where your repository is as a subdirectory of: 

    http:://server/hg

The right hand side is the absolute path on the server. It means you can type a relatively small path while remotely pushing and pulling. This instance:

    http:://server/hg/c82xx

Next up, as Mata pointed out, you need  to do hg init in the directory on the server, then from the local machine, push whatever you have already got to the server. So, in the directory with .hg on your local machine (in this case my c82xx project:

    hg push http:://server/hg/c82xx

There are two more vital thing to note though before you can do this:

1. You need to create, within the .hg directory on the SERVER a file called hgrc and put this in it:

[web]
push_ssl = false
allow_push = *

Now, from what I understand, you should ONLY do this on a trusted network. For me, I'm on a VPN or my LAN, so it's fine. 

2. That hgrc file AND all the repository directory and subdirectories have to have permissions to allow writing to these directories and folders. 

That should do it. Phew! 

I swear, version control is more complex than writing the software in the first place! :D 

Answers


Specifying a directory as config only works if it's a repository. You're pointing it to a directory which doesn't seem to be a repository.

Maybe you're trying to serve multiple repositories from within that directory? In that case you need to set config to point to a config file where you can then specify the repositories you want to include.

Have a look here, it should describe everything you need.


Need Your Help

How do I link in functions from a .cpp source file that also has a 'main'?

c++ gcc linker main multiple-definition-error

I want to use some functions from a .cpp source file that has a main function in my .cpp source file. (I'm building with make and gcc.)

Python MD5 not matching md5 in terminal

python hash md5

Hey guys, am getting MD5 of several files using python function