Making Git play nice on Windows

A while ago now I switched to Windows on my primary development machine. It’s pretty frustrating particularly when it comes to command line support but MozillaBuild goes a long way to giving me a more comfortable environment. One thing that took a long time to get working right though was full colour support from both mercurial and git. Git in particular is a problem because it uses a custom version of MSYS which seems to conflict with the stock MSYS in MozillaBuild leaving things broken if you don’t set it up just right. Since I just switched to a new machine I thought it would be useful to record how I got it working, perhaps more for my benefit than anything else, but perhaps others will find it useful too.

You want to install MozillaBuild, Mercurial and Git. MozillaBuild comes with Mercurial, but it’s generally an older version. This post assumes you put them in their default locations (on a 64-bit machine), so adjust accordingly if you changed that. When the Git installer asks choose the most conservative option, don’t put git in your PATH here.

You need some custom settings. First create a .hgrc file in your home directory or add the following to it if you already have one:



Now a .profile file in the same place:

export PATH="/c/Program Files/Mercurial":$PATH:"/c/Program Files (x86)/Git/bin"

The ordering is important there. $PATH will be set up to point to MozillaBuild (and other places) when you run the MozillaBuild startup scripts. You want the installed Mercurial to override the one in MozillaBuild and you want the MozillaBuild binaries to override the custom MSYS versions that Git comes with.

Finally you want a decent console to use. I’m using Console2 with general success. Install it, start it and go into its settings. Console2 supports creating custom tab types, so you can create a new MozillaBuild tab, or a new Windows console tab, etc. I like to do this so go to the “Tabs” section of the settings, click add and then give it a title of MozillaBuild. You then want to add the MozillaBuild startup script you want to use in the “Shell” option, e.g. “C:\mozilla-build\start-msvc10.bat” for me. If you’re feeling extravagant (and have a checkout of mozilla-central), point the icon to browser/branding/official/firefox.ico.

Some final useful settings, In “Hotkeys” assign Ctrl+T to “New Tab 1“. In “Mouse” set “Select Text” to the left button and “Paste Text” to the right button.

And that should be it. Open a new MozillaBuild tab in Console2. If you’ve done everything right you should see messages about the Visual Studio and SDK versions chosen. “which hg” and “which git” should show you the binaries in Program Files somewhere. They should both run and output in colour when useful.

Beating Bootcamp

I had a plan to go back to doing some more traditional Fractal work this weekend, unfortunately the best tools out there (UltraFractal is a fine example) tend to be on Windows and all my machines are Macs right now. So I figured it would be a simple task to use Bootcamp to install Windows onto my laptop, but like much else that I’ve tried to do these past few weeks it turned into a bit of a nightmare so I figured I’d document how I managed it.

The way Bootcamp works is relatively simple, it shrinks your main OSX partition and then creates a new Windows partition at the end of the disk, then you just install Windows onto that. The problem is that Bootcamp isn’t very good at shrinking the main partition when there are files sitting around at the end of it. As every good OSX fanboy tends to blather about, OSX works hard to avoid fragmentation within files, unfortunately I suspect this tends to spread individual files around all over the disk as the OS tries to find contiguous space to move them to. So when you try to use Bootcamp to shrink your partition you get this lovely error telling you that some files cannot be moved and suggesting you basically reinstall OSX to fix it:

Bootcamp failing to shrink your partition

There are lots of suggestions on the web for combating this. Most revolve around paying for defragmentation software. I didn’t want to pay though so here is a free alternative.

It should go without saying that this involves partition wrangling. Make sure you backup first, double check before doing every step, don’t blame me if you lose data.

Go get the Gparted live CD, burn it to a disk and boot from it (hold down Option while restarting). GParted should show your disk with two partitions in in, one small one at the start that claims to be FAT, ignore this one. The rest of the disk should be HFS+ and named after your Mac install. Select this partition, click the resize button and choose how much to shrink it by. The easiest way is to just put the amount of space you want for Windows in the space to leave at the end box. Click ok and then apply then wait patiently while it does a far more competent job than Bootcamp could of moving your files around.

Restart into OSX, open Disk Utility and go to the partition for your main disk. You should now see your OSX partition taking up less space and a gap at the end. Click the + sign to add a new FAT partition and name it BOOTCAMP. You should now find that the Bootcamp assistant recognises that the Windows partition exists and will allow you to start the Windows installation.

Make sure to read the bootcamp instructions, there are some real gotchas in there during the Windows install, and make sure to read the support info on how to allow Windows SP3 to install if you want to do that, without that I ended up with a broken Windows.