Installing Mecurial on Windows (Cygwin)

Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface. This tutorial uses Cygwin to install and work with Mercurial.

NOTE: after each line of code you type in - you need to hit the enter key.

Step 1: Download Cygwin

Cygwin is:

Download Cygwin:
http://www.cygwin.com/


Step 2: Install Cygwin

Click on the setup.exe file to begin the installation.

NOTE: We need to install several dependencies for Cygwin to work with Mercurial.

1

Click "Yes"

2

Click "Next >"

3

Click "Next >"

4

Click "Next >"

5

Navigate to the Desktop, then click "Next >"

6

Click "Next>"

8

Select a download site, it does not matter which one, then click "Next >"

9

Files are downloading.....

10

Click "Ok"

11

Type "wget" into the Search box, then click the "View" Button. Your screen should look like the screenshot below.

12

For package "wget" (second on list), click where it says "Skip". The box for wget should now be marked with an "X", as shown in the screenshot below.

13

Now type "mercurial" into the search box and click the "View" button .Click where it says "Skip". The box for mercurial with the category "Devel. Python" should now be marked with an "X", as shown in the screenshot below.

14

Now type "nano" into the search box and click the "View" button. Click where it says "Skip". The box for nano should now be marked with an "X", as shown in the screenshot below.

15

Now type "openssh" into the search box and click the "View" button. Click where it says "Skip". The box for openssh should now be marked with an "X", as shown in the screenshot below.

16

Click "Next >"

17

Click "Next>"

19

Packages are downloading and installing.....

20

Step 3: Install Bonjour

If you don't already have iTunes installed, download bonjour: http://support.apple.com/kb/DL999

Run the installer.

Step 4: Key files

You will receive and email from your instructor with the key files. You need to put key files (academy and academy.pub) where Mercurial can find them.

Open the Cygwin terminal

You will be in your home directory by default. Your prompt with look something like:

annakaziunasfrance@AKAZIUNA8765 ~
$

Where "YourUsername" is the username you created to login to Ubuntu.

Type the following text into the terminal after the prompt:
ls .ssh  

NOTE: If the system responds with a message like:
 ls: cannot access /home/akaziuna/.ssh: No such file or directory
then you need to create the .ssh folder. If you do not get this message, skip the command below.

Type:

mkdir .ssh        

Within the .ssh directory you need to create another directory called keys.
To do this type:

mkdir .ssh/keys

Download the keys that your instructor sent you in an email. They are named academy and academy.pub. You will need to place them in the keys directory.

To do this, save the key files from the email to:
Computer > Local Disc(C:) > cygwin > home > yourNameDirectory

Next, we need to change the permissions on the keys. You need to set permissions for your private key so that only you have read/write access to them.

Type:

chmod 644 academy.pub 

Then type:

chmod 600 academy
You need to move both of the keys from your desktop to the keys directory that you created earlier.

Type:

mv academy .ssh/keys
Then type:
mv academy.pub .ssh/keys

Both keys are now located in the .ssh directory.
You can check to see by typing:

ls -l .ssh/keys to list the contents of the directory.

You should see that academy and academy.pub are listed.

Step 5: Setting the Port

You will need to set the port that ssh uses to access fab.cba.mit.edu. You can do this by creating and editing a config file within your .ssh directory.

Type:

nano config

A text editor will open. Next we need to edit the file.

Add the following text to the text editor in the terminal window:

host fab.cba.mit.edu 
port 846 

To save the file:
- press [control]+O to save the file
- press [control]+X to exit the editor

Do not add any extension to the file name. Now we need to move it to the .ssh directory.

Type:

mv config .ssh/keys

Mercurial will ask you for a password. Ask your instructor for the password.

Step 6: Clone the archive

Now we need to clone the archive. For convenience, we will clone it to the desktop.

Copy the text and paste it into the terminal:

hg clone -e "ssh -p 846 -i ~/.ssh/keys/academy" ssh://hg@fab.cba.mit.edu/academy.2013 academy.2013

You should see the following response from the terminal as the archive is cloned. Success!

        requesting all changes
           adding changesets
           adding manifests
           adding file changes
           added 50 changesets with 141 changes to 101 files
           updating to branch default
           89 files updated, 0 files merged, 0 files removed, 0 files unresolved
           remote: buffer_get_ret: trying to get more bytes 4 than in buffer 0
           remote: buffer_get_string_ret: cannot extract length
           remote: key_from_blob: can't read key type
           remote: key_read: key_from_blob 
           remote:  failed  
NOTE: The number of files listed varies with the number of files in archive.

A folder named academy.2013 has been created in your home directory in the Cygwin folder. This folder contains the archive content.

You can navigate there through the GUI (Graphical User Interface) by clicking through the following folders: Computer > Local Disc(C:) > cygwin > home > yourNameDirectory

Step 7: Edit the Configuration File

Now you need to edit your archive's personal configuration file. To do this you need to move into the archive folder named "academy.2013" that you just created in your home directory.

Type:

cd academy.2013

You are now within the academy.2013 directory.

To edit your archive's personal configuration file (called hgrc) to reflect your name and email we need to open the file in a editior:

Type:

nano .hg/hgrc

A text editor will open inside the terminal window.

This text should already be in the file:

[paths]
default = ssh://hg@fab.cba.mit.edu/academy.2013
NOTE: Do not change this text, just add to it.

Put the following text in the file.

[ui]
username = First Last <user@machine.domain>
ssh = ssh -p 846 -i ~/.ssh/keys/academy -C
[hooks]
changegroup = hg update >&2  

To save the file:
- press [control]+O to save the file
- press [control]+X to exit the editor

Do not add an extension to the file name.

Step 8: Update Your Archive

Now try updating your archive by typing:

hg pull

you should see a response like this:

searching for changes
           no changes found
           remote: buffer_get_ret: trying to get more bytes 4 than in buffer 0
           remote: buffer_get_string_ret: cannot extract length
           remote: key_from_blob: can't read key type
           remote: key_read: key_from_blob 
         remote:  failed
Troubleshooting:
If you are asked for a password, then Mecurial can't find the keys or the key file permissions are wrong. (see step 4)

If it says something about port 22, then you probably forgot to edit the config file (see step 7)

Working With Mercurial

1. To get all changes from the MIT repository into your repository:

hg pull

To add new files

hg add

To commit changes

hg commit -m "MESSAGE"

To push files to server - Never force push!

hg push

Having Problems? Getting Strange Error Messages? - See:

Mercurial Troubleshooting

Tutorial by Anna Kaziunas France - Fab Academy AS220 Providence, RI - March 2012