Mercurial

From DreamHost

Jump to: navigation, search


Mercurial (official site) is a distributed version control system that is used track revisions of your files. You can find the unofficial manual here: (Distributed Revision Control with Mercurial).

Mercurial isn't currently installed by DreamHost (actually it appears that an old version 0.9.x is installed). This page will document how to install the latest version of Mercurial in your home account and get the webserver up and running. This is a work in progress.

Contents

How To Install Mercurial

  • Note: These instructions assume everything works with no problems. If you have any issues, please make a note and we can try and get them fixed.
  • Login to the shell account you would like to install Mercurial in
  • Download the latest Mercurial package (1.2.1 as of 10-Apr-2009)
   wget http://www.selenic.com/mercurial/release/mercurial-1.2.1.tar.gz
  • gunzip and untar the package
   tar xvzf mercurial-1.2.1.tar.gz
  • Change directory to mercurial-1.2.1
   cd mercurial-1.2.1
  • Run the make all command
   make all
  • Install the Mercurial package in your home directory. It will create bin, lib, and share directory in your home directory to install
   make install-home
  • Assuming your are using bash shell, you need to update your .bashrc and .bash_profile with the following lines (if you don't do this you will default to using an older version of mercurial already installed on the server).
   export PYTHONPATH=~/lib/python
   export PATH=~/bin:$PATH
  • Log out of your current shell session and log back in. Run the command hg --version and you should get the version information and copyright.
  • You may get an error message - *** failed to import extension hgext/hbisect: No module named demandload. This is due to the older installation specifying an extension called hbisect, which is no longer necessary. As you can't edit the system-wide configuration you can do the following:
   mkdir ~/.hgext
   touch ~/.hgext/dummy.py
   echo -e "[extensions]\nhgext.hbisect=~/.hgext/dummy.py" >> ~/.hgrc

How to Configure a DreamHost Account to Serve a Mercurial Repository

  • Note: These instructions are based on the instructions listed here ([1])
  • Login to you shell account
  • There needs to be a directory where the repository can be stored
   mkdir -p ~/hg/repos
  • Create the hgweb.config
   cat > ~/hg/hgweb.config
   [collections]
   repos/ = repos/
   [web]
   style = gitweb
   ^D
  • Copy the hgwebdir.cgi script to the hg directory
   cp ~/mercurial-1.1.2/hgwebdir.cgi ~/hg
   chmod +x ~/hg/hgwebdir.cgi
  • Open the hgwebdir.cgi and update the sys path
   vi ~/hg/hgwebdir.cgi
   Change the following two lines
     #import sys
     #sys.path.insert(0, "/path/to/python/lib")
   to
     import sys
     sys.path.insert(0, "/home/<user_name>/lib/python")
   <user_name> is your shell login name
  • Create a .htaccess file for the hg directory (Taken from [2])
   vi ~/hg/.htaccess
   Add the following lines (Comments optional)
     # Taken from http://www.pmwiki.org/wiki/Cookbook/CleanUrls#samedir
     # Used at http://ggap.sf.net/hg/
     Options +ExecCGI
     RewriteEngine On
     #write base depending on where the base url lives
     RewriteBase /hg
     RewriteRule ^$ hgwebdir.cgi  [L]
     # Send requests for files that exist to those files.
     RewriteCond %{REQUEST_FILENAME} !-f
     # Send requests for directories that exist to those directories.
     RewriteCond %{REQUEST_FILENAME} !-d
     # Send requests to hgwebdir.cgi, appending the rest of url.
     RewriteRule (.*) hgwebdir.cgi/$1  [QSA,L]
   save the file
  • Create a symbolic link to the hg directory in your domain
   cd to your domain directory
   ln -s ~/hg
  • Test the directory - http://<your-domain.com>/hg
    • You should see a web page that says "Mercurial Repositories"

Create a New Repository

  • Login to your shell account
  • Create a repository called my_first_repo
   hg init ~/hg/repos/my_first_repo
  • Create a hgrc file for the repository
   vi ~/hg/repos/my_first_repo/.hg/hgrc
   Add the following lines to this file
     [web]
     contact = <Your Name>
     description = My first Mercurial Repository
     push_ssl = false
  • Test your repository on DreamHost. First, make a file in your repository.
   cd ~/hg/repos/my_first_repo
   date >> my_first_file
   hg add
   hg commit -m "Added my_first_file to the repository"

On your home system, try to clone your repository.

   hg clone http://<your-domain>/hg/my_first_repo local_repo_copy
   cat local_repo_copy/my_first_file
  • By default, no one is allowed to push your repository. Read the next section, and review the Mercurial documentation on publishing repositories.

Securing your Repositories

  • Login to your shell account
  • Add this to the .htaccess file for the hg directory
       AuthUserFile /home/<username>/hg/hgweb.passwd
       AuthGroupFile /dev/null
       AuthName "My Mercurial Repository"
       AuthType Basic
       <Limit GET POST PUT>
           Require valid-user
       </Limit>
  • Create hgweb.passwd
       htpasswd -c -m ~/hg/hgweb.passwd <username>
  • Set up user names in the repo hgrc
       vi ~/hg/repos/my_first_repo/.hg/hgrc
       Add the following:
         allow_push = <comma-delimited username list>
  • "Trick" Mercurial into asking for authentication:
       touch ~/hg/failed_auth.html
  • You can avoid having to type in your user name and password each time by providing it when you clone the repository locally. If you did not clone the repository with a user name and password you can also update the .hg/hgrc of a local repository by updating the [paths] section.
       hg clone http://<user>:<password>@<your-domain.com>/hg <localdir>
Personal tools