Many of us like to code and program. It’s an awesome and very satisfying hobby. Yet keeping track of your progress and different versions of files and what modifications have been made to those files is no easy task when you have them spread right across your hard drive in various locations. Thankfully there is an easy way to manage your software development projects using Google Code and version control software Mercurial.
Google Code is a project hosting service operated by Google. It’s a fantastic service and very popular among the development community. And for good reason. It provides the user with access to a source code repository and gives you three options for your version control management. You can use the popular Git, Mercurial or Subversion.
Google Code also gives users a Wiki page for their project, Downloads directory, Bug reporting and tracking. The essentials to get your project running is all there. There are many other services on the internet that you might like to try. I am choosing to show you Google Code because it’s very simple to use and setup, even for beginners.
So head over to Google Code and set yourself up a new project to work on. And when prompted, ensure you choose Mercurial for your source code version control system.
Once you have your Google Code project page up and running, it’s now time to get writing some code and upload them to your new project.
I use zsh in the following tutorial, but you will probably be using Bash. The commands remain the same regardless of which shell you use.
The first thing we need to install is Mercurial. You can easily install Mercurial in OpenSUSE 12.3 by opening up a terminal and running the following command:
[email protected]:~> sudo zypper in mercurial
zypper will download and install the Mercurial package and required packages.
Retrieving repository 'openSUSE-12.3-Update' metadata ...................[done] Building repository 'openSUSE-12.3-Update' cache ........................[done] Loading repository data... Reading installed packages... Resolving package dependencies... The following NEW packages are going to be installed: mercurial mercurial-lang rcs The following recommended package was automatically selected: mercurial-lang 3 new packages to install. Overall download size: 2.4 MiB. After the operation, additional 10.9 MiB will be used. Continue? [y/n/?] (y): y Retrieving package rcs-5.8-1015.1.1.x86_64 (1/3), 232.0 KiB ( 1.1 MiB unpacked) Retrieving: rcs-5.8-1015.1.1.x86_64.rpm ...................[done (105.4 KiB/s)] Retrieving package mercurial-2.4.2-1.1.1.x86_64 (2/3), 1.4 MiB ( 5.7 MiB unpacked) Retrieving: mercurial-2.4.2-1.1.1.x86_64.rpm ..............[done (134.1 KiB/s)] Retrieving package mercurial-lang-2.4.2-1.1.1.noarch (3/3), 730.7 KiB ( 4.1 MiB unpacked) Retrieving: mercurial-lang-2.4.2-1.1.1.noarch.rpm .........[done (266.8 KiB/s)] (1/3) Installing: rcs-5.8-1015.1.1 ......................................[done] (2/3) Installing: mercurial-2.4.2-1.1.1 .................................[done] (3/3) Installing: mercurial-lang-2.4.2-1.1.1 ............................[done]
The first thing you will want to do is clone your Google Code source code repository to your home directory ~/
For the next command, you need to go to your Google Code project page and click on the Source tab. This will present you with the correct details to enter in to your terminal to clone your Mercurial repository to your own system.
This is easily done by punching the correct command in to your terminal. But make sure you enter the correct repository details for this to work correctly:
[email protected]:~> hg clone https://firstname.lastname@example.org/p/project-name/ destination directory: project-name requesting all changes adding changesets adding manifests adding file changes added 2 changesets with 2 changes to 2 files updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
Now it’s time to jump in to the new local directory which has been cloned:
[email protected]:~> cd project-name
Now let’s have a look at what is in the directory:
[email protected]:~/project-name> ls -a . .. .hg file_1.txt file_2.txt
You will notice I have a couple of files in the directory already. If your project is new, your own will probably display more something like this:
[email protected]:~/project-name> ls -a . .. .hg
The .hg directory holds an important file that we need to configure in order to proceed any further. I use Emacs for most of my development work, so I entered the following:
[email protected]:~/project-name> emacs .hg/hgrc
If you don’t use Emacs or don’t have it installed, you can just use the default KDE text editor by using the following command. The result will be the same:
[email protected]:~/project-name> kwrite .hg/hgrc
The .hg/hgrc configuration will look something like this:
[paths] default = https://email@example.com/p/project-name/
This is the correct directory that Mercurial requires for working with your source code repository on Google Code. But it’s not enough information required for pushing updates to Google Code.
You must enter the following information to make the configuration file complete:
[paths] default = https://firstname.lastname@example.org/p/project-name/ [ui] username = yourusername <email@example.com>
Now we are ready to upload your source code files to your Google Code project. Once you have the files ready to upload, you need to copy them in to your local repository directory. Here is my own example:
[email protected]:~/project-name> cp ../LICENCE.txt .
[email protected]:~/project-name> ls LICENCE.txt file_1.txt file_2.txt
LICENCE.txt is the new file that I have copied in to the local repository directory. So now we need to tell Mercurial there is something new that has been added.
[email protected]:~/project-name> hg add adding LICENCE.txt
And now we need to commit the changes. The following command launches vim. This is where you can enter your changes and notes for the commit you are performing:
[email protected]:~/project-name> hg commit
Once you’ve entered your notes, exit vim by entering:
Your commit details are now saved. Now we need to push the changes to the Google Code source code repository. This is easily done by doing the following and entering your password when prompted:
[email protected]:~/project-name> hg push pushing to https://firstname.lastname@example.org/p/project-name/ searching for changes http authorization required realm: Google Code hg Repository user: your-username password: ********
It’s very important to remember your Google Code Mercurial password is different to that of your usual Google Account password. This is something that always causes confusion with new users to Google Code. Your Mercurial password to be used for Google Code can be found by logging in to your Google Code project and in the upper right-hand corner of the page, you will see Profile next to your username. Click on Profile. And then click on the Settings tab. You should now see your Mercurial password you need to use for pushing changes to your project.
Once you have entered the correct password, you should see the following confirmation message:
That’s it. You now have a running Google Code and Mercurial source code version control system running successfully.