Thursday, April 15, 2010

Git Bash and GUI from Eclipse

At work, we've almost migrated all of our projects from Subversion to Git. We only have one left that is currently being worked on.

Even though there isn't much support for using Git within Eclipse, and none that I'd trust to keep up to date and maintain good usage with Git for Windows, I'd still like to access Git tools from the Eclipse IDE.

I found a reference to Part I and Part II on YouTube, on how to set up Git Bash for your whole workspace. Except I don't quite use Eclipse like that, so I use {&project_loc} instead of {&workspace_loc} to start the specific project I'm working on, rather than the whole workspace.

Not satisfied with just having Git GUI launching from Eclipse, I also wanted Git Bash as well. This was a little tricker.

You need to set up an External Tool, similar to the one done for Git GUI, except target your cmd.exe (C:\WINDOWS\system32\cmd.exe), and use the following as the arguments:

/c start "Git Bash" "C:\Program Files\Git\bin\sh.exe" --login -i

This ensures that a new command window is launched, just like regular Git Bash, and that the shell provided by the Git install is run. If you don't include the "start", then you end up with the shell running in an Eclipse Console. And I'm not a fan, especially when it comes to handling ANSI escape sequences, as Git Bash is likely to do now and again.

Remember to deselect the "Allocate Console (necessary for input)" checkbox in the Standard Input and Output fieldset of the Common tab, and you won't end up with a process running in the console, anyway.

The only downside with this is that by targeting {&project_loc}, I need to have an project selected. I may just end up setting this to my root projects directory, where all my projects are listed underneath. Then I can just cd to the directory I'm interested in playing with, and the launcher will work, no matter what project I have nor have not selected.