In case you are not familiar with Mercurial (Hg), it is a Distributed Version Control System (DVCS) aimed at simplifying revision control. The purpose of this post is not to introduce Mercurial, but you can read more about Mercurial at the following links to get better acquainted with the software:
- HgInit | Joel Spolsky’s detailed introduction to Mercurial
- Mercurial: The Definitive Guide | A comprehensive guide to using Mercurial
- Mercurial vs. Git Comparison | Google Code wiki analysis of two DVCS solutions
- Official Mercurial Wiki | Selenic’s official Mercurial wiki and guides
Now that we are all comfortable with Hg (the chemical symbol for Mercury and nickname for Mercurial), I would like to take present an issue I spent some time working on today. There are several different publishing mechanisms in Mercurial, but for the setup at my company we decided to simply use http being that our provider is only internally available and protected by several firewalls and other security measures. We chose this approach over the more popular SSH publishing mechanism being that we are hosting our Mercurial installation on a Windows 2008 R2 server. Had we installed it on a box running something other than Windows, SSH would have solved the problem I’m about to describe below. Here’s a quick view of our basic setup:
One limitation when using http as a publishing mechanism is that you cannot create a repository remotely; no if, ands, or buts about it. Another twist was that our CM (Configuration Management) procedures dictate that our developers are not permitted to RDP into the Mercurial server. This left us trying to decide how to allow developers to create repositories remotely since our http communication channel does not allow remote repository creation.
Troy Goode, a good friend and colleague, suggested that we leverage PowerShell to solve the problem. After spending a little bit of time with the Configuration Manager a PowerShell solution was in place. Using the following basic PowerShell command, a remote session was initiated without making the developer an administrator on the machine with RDP access:
ENTER-PSSession your-server-name-or-ipaddress
I originally encountered an Access Denied error, which we discovered was caused by my account not have the appropriate permissions on the Mercurial server to create a remote PowerShell session. This is pretty easy to remedy and you can read more about it on the TechNet library page. Simply execute the following cmdlet on the server to manage the PowerShell remote session security configuration:
set-pssessionConfiguration -name Microsoft.PowerShell -showSecurityDescriptorUI
The last change is to set the appropriate directory permissions on the remote server to the location where developers are permitted to create repositories. That should be straightforward enough without going into any examples since repository architectures can differ drastically.
It can’t be that easy, can it? Well, good news – it is that simple! With those changes you should be able to remote manage (create and delete) your Mercurial (Hg) repositories via PowerShell. Hopefully this helps you save some time in your setup of Mercurial – a very awesome, and my current favorite, Version Control System.