A. Installing and configuring Apache with Mercurial
And here we go...
The first thing we have to do is install python (Mercurial is developed on python and mercurial packages):
sudo apt-get install python python-dev mercurial
The next step is create our repository folder, and give it the appropriated permissions from where Apache will interact:
sudo mkdir -p /var/hg/repos
sudo touch /var/hg/hgweb.config
sudo chown -R www-data:www-data /var/hg
sudo touch /var/hg/hgweb.config
sudo chown -R www-data:www-data /var/hg
Edit the file /var/hg/hgweb.config that you just created and include the following Mercurial configuration directives:
[collections]
repos/ = repos/
[web]
style = gitweb
Now we are going to copy a little script that will allow to interact apache with our Mercurial repository and again we will set the correct permissions:
cd /var/hg/
sudo cp /usr/share/doc/mercurial/examples/hgwebdir.cgi ./
sudo chown www-data:www-data ./hgwebdir.cgi
sudo chmod +x ./hgwebdir.cgi
sudo chown www-data:www-data ./hgwebdir.cgi
sudo chmod +x ./hgwebdir.cgi
In the following step we are going to initialize a repository called 'myRepos', this is the general way to do it, so if in the future you need to initialize another repository you just need to execute this command again by changing the name of 'myRepos' by the new name.
sudo su - www-data -c "hg init /var/hg/repos/myRepos"
Edit your new repository config file /var/hg/repos/myRepos/.hg/hgrc to include information about itself and allow push from everywhere (push is mercurial terminology)
[web]
contact = Javier
description = My first Mercurial repository
allow_push = *
# Allow the download for the last snapshot in compacted format
allow_archive = gz zip bz2
contact = Javier
description = My first Mercurial repository
allow_push = *
# Allow the download for the last snapshot in compacted format
allow_archive = gz zip bz2
And last but not least we have to configure Apache to start serving from our repository, this is done by adding the following section on the /etc/apache2/sites-available/default-ssl:
AddHandler cgi-script .cgi
ScriptAliasMatch ^/hg(.*) /var/hg/hgwebdir.cgi$1
<Directory "/var/hg">
Options FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
AuthType Basic
AuthName "Password Required"
AuthUserFile /etc/apache2/passwd/passwords
Require valid-user
</Directory>
You can place it right after the <Directory /var/www/> section so your config file will looks like:
...
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AuthType Basic
AuthName "Password Required"
AuthUserFile /etc/apache2/passwd/passwords
Require valid-user
</Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AuthType Basic
AuthName "Password Required"
AuthUserFile /etc/apache2/passwd/passwords
Require valid-user
</Directory>
AddHandler cgi-script .cgi
ScriptAliasMatch ^/hg(.*) /var/hg/hgwebdir.cgi$1
<Directory "/var/hg">
Options FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
AuthType Basic
AuthName "Password Required"
AuthUserFile /etc/apache2/passwd/passwords
Require valid-user
</Directory>
...
Restart apache:
sudo apache2ctl restart
And that's all!! You can now access to your repository via web:
B. Using mercurial from our local machine
First of all you will need to install Mercurial in your local machine:
sudo apt-get install mercurial mercurial-common
Now that we have created a remote repository, we can clone it locally an perform our changes:
(From your local pc)
mkdir ~/MercurialRepositories
cd ~/MercurialRepositories
hg clone https://ec2-46-137-60-179.eu-west-1.compute.amazonaws.com/hg/myRepos/
You will receive a set of messages as following:
warning: ec2-46-137-60-179.eu-west-1.compute.amazonaws.com certificate with fingerprint 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58 not verified (check hostfingerprints or web.cacerts config setting)
http authorization required
realm: Password Required
user: javier
password:
warning: ec2-46-137-60-179.eu-west-1.compute.amazonaws.com certificate with fingerprint 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58 not verified (check hostfingerprints or web.cacerts config setting)
destination directory: myRepos
warning: ec2-46-137-60-179.eu-west-1.compute.amazonaws.com certificate with fingerprint 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58 not verified (check hostfingerprints or web.cacerts config setting)
no changes found
updating to branch default
resolving manifests
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
http authorization required
realm: Password Required
user: javier
password:
warning: ec2-46-137-60-179.eu-west-1.compute.amazonaws.com certificate with fingerprint 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58 not verified (check hostfingerprints or web.cacerts config setting)
destination directory: myRepos
warning: ec2-46-137-60-179.eu-west-1.compute.amazonaws.com certificate with fingerprint 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58 not verified (check hostfingerprints or web.cacerts config setting)
no changes found
updating to branch default
resolving manifests
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
If you want to avoid all these annoying warnings just edit the file ~/MercurialRepositories/myRepos/.hg/hgrc
And add the following lines:
[hostfingerprints]
ec2-46-137-60-179.eu-west-1.compute.amazonaws.com = 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58
ec2-46-137-60-179.eu-west-1.compute.amazonaws.com = 6a:11:f3:d4:be:ed:54:f3:d3:78:ca:6b:03:58:55:b0:3b:25:44:58
Where the value of the fingerprint is the one displayed on the warning
Resources
APENDIX
A. Some useful commands on mercurial:
hg sum
Shows state of the working directory (include info of the repository).
--remote (shows if there are incomings)
hg st
Shows differences of the working directory with the current working repository.
hg resolve -m <file>
Mark file as resolved (we have to make a commit afterwards)
hg incoming
Show if there is a new changeset coming from the central repository
-p Show the differences between files
hg outcoming
Show if there is a new changeset going to the central repository
0 comments:
Post a Comment