Showing posts with label Source Control. Show all posts
Showing posts with label Source Control. Show all posts

Friday, 11 June 2010

Quick and simple Mercurial (Hg) setup

I thought the time had come for me to get to grips with a DVCS having heard so much love for Git and Hg. The first big decision; Hg or Git? And this is a tough one, because everything I've heard about the two indicates that there's only minimal differences. Someone I know at work has been trying Git, so to get a comparative test I thought Mercurial. Besides, I prefer the name Mercurial (heard about it before Git) and I like the references to the periodic table of elements (Hg); it tickes my geek.

Joel Spolsky wrote a great guide that's available at http://hginit.com/. It's great not only because it helps show people the path to DVCS from SVN (or similar VCSs) but because he does it with the right amount of humour. Even if you don't want to adopt Hg or Git, it's a fun read.

But it jumps right in assuming you, or your IT support team, have already installed Mercurial for you. So here's my guide to getting it all installed and configured.

Where to get the goods:

  1. Get the actual Mercurial installation here: http://mercurial.selenic.com/ 5.91MB
  2. Get VisualHG, a Mercurial Source Control Plugin for MS Visual Studio here: http://visualhg.codeplex.com/ 337kb
  3. Get TortoiseHg here: http://tortoisehg.bitbucket.org/ 21.4MB

Total download: 27.6MB

Installation

Since the first download is an MSI there's really not much to is. Run the MSI. I chose not to install the translations. At the time of writing this was Mercurial 1.5.4. Installation was uneventful as expected. It installed to C:\Program&nsbp;Files&nsbp;(x86)\Mercurial. You guessed it, I'm running 64-bit Windows 7 and Mercurial installed 32-bit. Ho hum. The start menu folder contains links to things like help on the configuration file that made me think I was on Unix again and nearly run for the hills. So I ignored that for now. The link to the command reference seemed equally foreboding so I just opened a command line prompt to see what "hg" would do. At last, a simple list of commands. That confirmed I had it installed and from here I could follow Joel's superb tutorial if I wanted.

Much as I love the command line. Really; I do. Maybe because my first experiences with an IBM PC were with DOS, who knows. Nevertheless, I know that I will not check in as frequently as I ought to if I have to drop to the command line rather than perform these tasks from within my IDE of choice. My IDE of choice is of course, Visual Studio. I love it and I HATE it. But there seems no viable alternative at the moment, so I try focus on the love I have for it. Time now for the second install - VisualHG from CodePlex.

Again, this is an MSI, so it's so straight forward it's practically boring. Again 32-bit (installed to C:\Program Files (x86)\VisualHG\ by default). Installation was particularly quick. One of those moments when you wonder whether it installed correctly. Their installation instructions call for installing TortoiseHg, but I don't feel a need for Explorer integration so I'm not installing that - yet. It's as simple as opening Tools-Options and selecting VisualHG from the Source Control Plug-in selection drop down box. I'm again surprised by how simple this is. I am beginning to feel that sense of pending doom: it's easy; too easy...

Now creating a new project under Mercurial control might not be easy - I've not created a repository yet. Let's see...

Created a new ASP MVC 2 web application. An attempt to commit tells me it's not under Mercurial source control. Well duh. Time to refer to Joel's tutorial...

I go to the folder where the files are, just like he tells me to, and I type "hg init" and hit Enter. Nothing. Ah but hang on, Joel said that would happen. Look and see that the ".hg folder is there". Amazed; I pause. Nothing has ever been that fast before, not even Subversion. I savour the moment. If this is a sign of things to come, bring it ON!

First issue occurs after I've done "hg add" and I try "hg commit". It throws this back at me:

abort: no username supplied (see "hg help config")

I'm starting to guess here. It tells me where it'll look for configuration files so I create a new text file in "C:\Users\bhofmann" called "Mercurial.ini" that it should read from. The contents resemble the following:

[ui]
username = Bernhard Hofmann
verbose = True

I try the "hg commit" command again and woot! It opens Notepad with a list of the files (just like in Joel's tutorial). I exit and save, and it whirls through the files. Maybe there's a plugin for AD support or something, because the ability to spoof identities seems too easy. Still, I trust me and I'm the only one using this repository - for now.

Back to Visual Studio to see what's happened there...

It would appear that TortoiseHg is indeed required for VisualHg. I decide to watch Rob Connery's video: http://tekpub.com/codeplex. As good as the video is, my time is limited and it's WAY too slow.

I install the 64-bit TortoiseHg MSI. Once again installation is boringly simple and robust. Kudos to the testers on all these products.

Start Visual Studio and the difference is obvious - suddenly I have icons showing the status of each file. Sadly the pending changes and source control explorer windows are TFS-only tools.

Job done - I can edit, commit, see history and revert files all from within VS2010.

Next steps will be to see how I push up to a central repository, and how I make backups. Or maybe that's just a question of having another repository I push to?

Monday, 24 November 2008

Setting up source control

I have from time to time had to set up source control on a new system, or after formatting a system that's grown old over time. The steps are pretty simple if you follow the instructions, but they can ramble on a bit in my opinion. I want something short and quick to follow, so when I decided to put source control on a new development box I decided to post this as much for myself as for anyone else.

Steps to setting up Subversion source control

The steps below describe how to set up source control for local use and do not require installation of an Apache web server to allow remote access.

  1. Download and install SVN
  2. I chose Slik Subversion. The same page has links to AnkhSVN (see below). Installation was smooth but for the registration of the service (didn't happen, and no error message). The command line to register my installation of the service was:

    sc create Subversion binpath= "C:\Program Files\SlikSvn\bin\svnserve.exe --service --root D:\Repository.SVN" displayname= "Subversion" depend= Tcpip start= auto

    I ran into the following error because by default on Vista, all things run as normal user.

    [SC] OpenSCManager FAILED 5: Access is denied.

    Screenshot showing how to set a command prompt to run with admin rightsThe solution is pretty simple; you make the command line run as administrator as follows: Edit the properties of the command line link and on the [Shortcut] tab, press the [Advanced...] button and then tick the [Run as administrator] option. Press OK twice to close the properties and then run the command line. You might be prompted to continue with administrator rights.

  3. Download and Install AnkhSVN
  4. If you want Visual Studio integration (and who would not want this?) you need a client tool such as AnkhSVN.

    Installation was simple, and it registered with both VS2005 and VS2008 on my system. The new version has icons that show the checked out/in status of each file under source control. It also has very good integration with the pending changes and a neat history viewer.

  5. Install TortoiseSVN
  6. This shell extension will highlight which files and folders are under source control by embellishing their icons with indicators. Tortoise also has a useful repository browser which can be loaded from an explorer context menu when no file is selected.

  7. Backup
  8. No installation of source control is complete if you aren't backing up that repository. Schedule a task to run as frequently as you desire. I used the svnadmin program to make a hotcopy of the repository/ies I have. Using the same example repositoryy as above, the backup is done with one simple command:

    svnadmin hotcopy D:\Repository.svn c:\backup\D_Repository.svn

    New entry 14 June 2009: I've just written a batch file to perform the backup and compress the backed up repository to a ZIP file with the current date. I know I'll need this again, so I'm posting it here. The two things to care for are highlighted in yellow.

    @echo off
    set backupDT=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
    set backupFolder=Backup_Repository_%backupDT%.svn
    echo Removing existing backup folder
    rd %backupFolder% /S /Q
    echo Backing up repository to %backupFolder%
    svnadmin hotcopy C:\repository\Svn %backupFolder%
    set backupZipFilename=SvnBackup_%backupDT%.zip
    echo Compressing repository into %backupZipFilename%
    D:\UTIL\zip -r -9 -S -o %backupZipFilename% %backupFolder% > nul
    echo Removing backup folder (contents are in ZIP)
    rd %backupFolder% /S /Q
    pause