Go Help

Mercurial Version Control

Introduction

In order to install the Go language, you must have the Mercurial  version control system installed ( hg is the chemical abbreviation for Mercury).  Since I needed to learn the basics of Mercurial to keep Go updated, I decided to use it as my version control system.  You will also need to use it if you decide to contribute to the Go project. My previous experience was with Perforce.  I have found Mercurial to be an elegant, straight forward, lightweight, peer oriented system.  It works well for a single developer and should be good for many types of larger projects, especially open source type projects.  It works for any text file, so you can use it for your Go source files, make files, documentation, etc.  It does not work well on binaries, pictures, word processor format files, etc.

Installation

Under Ubuntu 9.10, the repositories install version 1.3.x.  Ubuntu 10.4 installs version 1.4.3.  This seems to work fine, but if you want the latest version of  Mercurial 1.5.x, with the latest bug fixes, here is the link:    https://launchpad.net/~mercurial-ppa/+archive/releases.  When you get there, go down and click Technical details about this PPA.  Just below that will come up Read about Installing.  Click this and follow the instructions in the pop up window.  You will need this version if you want to install Tortoisehg integration for Nautilus, more later.

Here is a nice video on installing both Mercurial Version Control and TortoiseHG:  http://blog.ragingfx.com/mercurial-with-tortoisehg-installation-ubuntu

Learning

  1. Mercurial Home Page
  2. Learning Mercurial Workflows – An excellent getting started guide
  3. Mercurial – The Definitive Guide – The best reference book
  4. Hg Init: a Mercurial tutorial – A step by step tutorial
  5. Mercurial by Example – An example based tutorial

The Basics

I will start with The Basics using a terminal command line.  Further chapters will show some Gedit integration, basic Nautilus integration and then Nautilus integration with TortoiseHg.

Below, I will add my comments to Learning Mercurial Workflows section Basic Workflows.    Open a terminal.

1.  Open or create the $HOME/.hgrc file with Gedit to create your user id. (see Learning Mercurial Workflows) here is mine:

# johng Mercurial hgrc file

# this enables these 2 extensions
[extensions]
hgext.graphlog =
hgext.extdiff =

# set your user name and an external merge program
[ui]
merge = meld
username = johng

# set diff program for Nautilus plugin tortoisehg
[tortoisehg]
vdiff = meld

2.  Initialize the project for Mercurial.  I recommend that you create your own project directory, separate from the Go directory, to keep the Go directory clean, I called mine ‘GoMyProject’.  Go will find what it needs from the environment and path settings.  For example: hg init GoMyProject , will create your directory and add the Mercurial repository.  Or create your project directory and change to it and type hg init .

3.  Add files to Mercurial.  You can mark everything in the current directory to be added. For example: hg add , or add files one at a time, For example: hg add ‘filename’.  The Chapter Mercurial in Gedit also has an external tool for adding files.

4.  If you create a file .hgignore in your project directory, then Mercurial will ignore files that match those patterns for version control.  Below is what I use.  Copy and paste this into a new document in Gedit and save as ‘.hgignore’ in your project directory, edit as you wish with regex patterns.

syntax: glob

# File patterns for Mercurial to ignore
# This line is a comment, and will be skipped.
# Empty lines are skipped too.

# Backup files left behind by the Gedit editor.
*~

# Executables for Go
*.out

# Link files for Go
*.6
*.8

# Backup and Temp files
*.bak
*.tmp

# This file and other hidden files
.*

# Lock files used by the Emacs editor.
# Notice that the “#” character is quoted with a backslash.
# This prevents it from being interpreted as starting a comment.
#.\#*

# Temporary files used by the vim editor.
#.*.swp

5.  Continue following the ‘Learning Mercurial Workflows’ for hg status, hg diff, hg commit, hg log, hg update.  Go on to Lone Developer.  More detailed information is found in the well written Mercurial Definitive Guide.

Next Mercurial integration into Gedit.

Blog at WordPress.com.

%d bloggers like this: