|
![]()
|
Support sites: Documentation | Forum | Control panel | Status blog | Tickets
Mercurial, commonly referred to as Hg (the symbol for the element Mercury), is an open source distributed version control system.
It’s easy to install Mercurial. To install Mercurial:
Open an SSH session to your account.
Enter easy_install Mercurial and press Enter.
Note
You can specify which Python version to use to install Mercurial by entering easy_install-X.Y Mercurial where X.Y is a Python version number. For example, to use Python 2.5, enter easy_install-2.5 Mercurial.
Open ~/.hgrc in a text editor.
Add the following lines to ~/.hgrc:
[ui]
username = name <your_email_address>
subtituting name and your_email_address with the name and email address you would like to have appear by default in commits made from your Mercurial installation.
Save and close the file.
You can now use the command line tool hg to work with Mercurial repositories. Enter hg help and press Enter for a complete list of commands. To learn more about using Mercurial, check out the official Quick Start guide and the Mercurial book.
You can create an application to serve hgwebdir.cgi (also known as HgWeb), which makes it easy to view repositories with a web browser, as well as push and pull changes over HTTPS.
Note
These directions assume you already have Mercurial installed. If you have not already installed Mercurial, please see Installing Mercurial.
The first step in serving Mercurial repositories is to create an application to serve the CGI script.
) button. The Add page
appears.Next, a directory needs to be created where the repositories themselves will be stored. Typically, this will be a directory outside of the Static/CGI/PHP application’s directory.
Now, download the Mercurial sources, which contain a CGI script which will make repositories available on the Web.
Now, configure hgwebdir.cgi so it knows where to look for your Mercurial installation and repositories.
Open an SSH session to your account.
Change to the Static/CGI/PHP application’s directory. Enter cd ~/webapps/static_cgi_php_app_name/ and press Enter.
Make hgwebdir.cgi executable. Enter chmod u+x hgwebdir.cgi and press Enter.
Open hgwebdir.cgi in a text editor.
If you installed Mercurial with a Python or easy_install version other than the default, edit this line:
#!/usr/bin/env python
by replacing python with pythonX.Y, where X and Y are the major and minor version numbers of Python, respectively.
Uncomment these lines:
#import sys
#sys.path.insert(0, "/path/to/python/lib")
and replace "/path/to/python/lib" with the path to the directory where you installed Mercurial. If you used the default easy_install, this directory will be /home/username/lib/python2.4.
Save and close the file.
Open a new file named hgweb.config.
Edit the file so that it looks like the following:
[paths]
/ = /path/to/repositories/**
where /path/to/repositories is the path to your Mercurial repositories (for example, /home/username/hg).
Note
The asterisks (*) are required for hgwebdir.cgi to find your repositories; they permit hgwebdir.cgi to find Mercurial repositories which are in a subdirectory of the path specified.
Save and close the file.
The next step in publishing your Mercurial repositories is to instruct Apache to use hgwebdir.cgi to respond to requests.
Open an SSH session to your account.
Change to the Static/CGI/PHP application’s directory. Enter cd ~/webapps/static_cgi_php_app_name/ and press Enter.
Open a new file named .htaccess.
Edit the file so that it looks like the following:
Options +ExecCGI
RewriteEngine On
# / for root directory; specify a complete path from / for others
RewriteBase /
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
Note
If you will not be hosting your repositories from the root URL path, replace RewriteBase / with RewriteBase /path/to/directory. For example, if you were to host your repositories at http://www.example.tld/hg you would substitute RewriteBase / with RewriteBase /hg.
Save and close the file.
Finally, it’s time to create a website entry so that requests can be proxied from a URL to hgwebdir.cgi‘s application.
). The Add
page appears.
). An additional row in
the Site apps table appears.You can now visit the domain and path specified in the website entry to see your Mercurial repositories. The listing is probably empty now, however; create new repositories with hg init in your repository directory to populate the list.
Now that you have a working repository browser, you can enable pushing to those repositories over HTTPS for authenticated users.
Open an SSH session to your account.
Change to the Static/CGI/PHP application’s directory. Enter cd ~/webapps/static_cgi_php_app_name/ and press Enter.
Open .htaccess in a text editor.
Add the following lines to the bottom of .htaccess to permit pushes only by authenticated users:
AuthType Basic
AuthName MyHgWebDir
AuthUserFile /home/<username>/webapps/<static_cgi_php_app>/.htpasswd
<Limit POST PUT>
Require valid-user
</Limit>
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
where <username> is your username and <static_cgi_php_app> is the name of the Static/CGI/PHP application.
Note
Alternatively, you can use the following lines to prohibit all access except for authenticated users:
AuthType Basic AuthName MyHgWebDir AuthUserFile /home/<username>/webapps/<static_cgi_php_app>/.htpasswd Require valid-user <Files ~ "^\.ht"> Order allow,deny Deny from all </Files>
Save and close the file.
Now, create an initial username and password that can push to the repositories. Enter htpasswd -c .htpasswd username and press Enter. A prompt appears for a password.
Enter the password for the new user and press Enter. A prompt to confirm the password appears.
Enter the password again and press Enter.
Open hgweb.config in a text editor.
Add the following lines to the file:
[web]
allow_push = *
Note
Alternatively, you can replace * with a comma separated list of users authorized to push. Or, for more finely grained control, you can add these lines on a repository-by-repository basis in the repositories’ .hg/hgrc file.
Save and close the file.
You can now push to the repositories as an authenticated user.