Tuesday, February 19, 2013

Using git flow in eclipse

Git flow is a great way to improve your development process. It helps in setting up dedicated branches for development, releases and fixes. If you are not familiar with git flow please read a successful git branching model before continuing. Git flow is extremely easy to use and really worth a try.

Git flow is currently not integrated in eclipse (see bug 348610), so we need to use a command line to use it. Basically I love the power of command lines but when using an IDE I prefer visual support, so lets find a way to make this a bit more user friendly.

For this tutorial I assume you are using windows (if you were on linux you would love your bash anyway).

Step 1: Installing msysgit

As we need to enter commands on the command line we need to install the necessary tools for that, no way to avoid that.

Download and install the latest version of Git. At the time of writing this is v1.8.1.2. Go with the default settings when asked for the components and select Run Git from the Windows Command Prompt when asked for Adjusting your PATH environment. Line endings can be configured as you prefer.

You need to log off so your PATH variable will be updated accordingly. Afterwards you should be able to use the git command in a console.

Step 2: Installing git flow

Now we need to install the git flow addon. Here is a short excerpt of the install wiki page:

We need 2 additional files to download and copy to our msysgit/bin folder:
Go to the util-linux-ng download site and download the Binaries zip. From there extract only getopt.exe. Then download Dependencies zip to extraxt libintl3.dll.

During the setup we need to create a temporary directory. Open a command shell and switch to your temp directory
cd temp
git clone --recursive git://github.com/nvie/gitflow.git
cd gitflow
contrib\msysgit-install.cmd
The install command should work if you are using the default install locatin for msysgit. If it still cannot find msysgit you have to provide the install location as a parameter.

Afterwards try to run gitflow by entering
git flow
in a shell. If it works you can safely remove your temporary install folder.

Step 3: Using git flow

We are ready to use git flow by now from our shell. So give it a try, best following the blog post by Jeff Kreeftmeijer: Why aren't you using git-flow?

Step 4: Adding a shell to eclipse

WickedShell is a nice plugin for eclipse that integrates a shell into the IDE. Install it and restart your IDE. Now you can open a new view Wicked Shell / Shell which basically gives you a command prompt on windows. While you can use the windows shell I would rather go with bash.

To activate it go to Preferences / Wicked Shell and select Cygwin - Bash as Default Static Shell. To make it work you need to provide your msysgit install directory under Shell root directory (do not provide the bin dir, but its parent).

You can change the Active Shell in the view menu of the Shell view.

You may see some strange characters on the prompt by now. These are control codes which cannot be displayed by the SWT widget (at least not the way wicked shell is implemented). So we need to change the prompt. Find your home directory (enter: cd ~;pwd) and create a .bashrc file with following content:
PS1='\w $ '
You should not exchange the $ sign at the end as it is used as command delimiter token by wicked shell. If you go with some other character, wicked shell will automatically insert a $ when you type your first character.

Considerations

WickedShell seems to have its limitations. So it is not possible to send a CTRL-C in a shell. I also experienced problems when trying to enter text a command prompts for (therefore the git flow init command does not work). Fortunately you need only single line commands once git flow is initialized correctly. If you need a full shell you could still Open an external Shell from the Shell view menu.

I tested WickedShell on Windows 7, according to the bugtracker there seems to be no support for Windows 8 yet.

2 comments:

  1. Thank you for this. I have a question though, when I select a project on the left panel and right click to "Change to folder in Shell" .. Wicked Shell is trying to do:
    cd /cygdrive/c/projects

    that /cygdrive by default attached to the "cd" command ... is there a way to get rid of it?

    ReplyDelete
    Replies
    1. Sorry, I do not work with wickedShell that often. I see there is a mailing list for wicked shell. Better ask the devs directly.

      Delete