Gold Apple Software Web Development by Geoff Appleby

Using Eclipse and EGit for Drupal Development

Drupal will be migrating from CVS to Git (hopefully) soon, so there are benefits to introducing Git to your current workflow.  While CVS remains the primary code repository for Drupal projects, a Git mirror has been set up for some time and can be used now.  EGit is a team plugin for Eclipse that enables you to manage Git repositories from within Eclipse, utilizing a Java port of Git so that it is entirely self-contained.  Though it is under active development, it looks to have made some big strides in a short period and is likely suitable for most users.

Installing EGit

Go to Help -> Install New Software... in the menu bar and click Add Site in the dialog. After entering a name and the update URI, you may have to select the new update site in the top drop down. Select the EGit and JGit (without source) packages and follow the install process.  You'll likely have to review the packages to be installed, accept the licensing terms, and then restart Eclipse to finish.

Screenshot - Install New Software Screenshot - Install New Software - Add Update Site Screenshot - Install New Software - Select Packages

Cloning a repository

The first place to start is by opening the Git Repository Exploring perspective (Window -> Open Perspective); this is the easiest place to manage your repositories and settings.  You can safely close the editor view to gain more space for the Git Repositores view and Properties view.

Click the 'Clone Repository' icon and enter the host and repository path; the URI value will be filled automatically but is helpful if you copy and paste a path from elsewhere[1].  Select the git protocol and leave the port field empty to use the default.

The next window allows you to select which branches you would like to copy locally.  I prefer to select all values but you can safely leave older, unmaintained branches (e.g. 3.x/4.x) and download them later if necessary.

The final window allows you to select a path to store your repository, defaulting to a folder in your workspace with the same name as the repository.  Due to naming conflicts with my CVS copies of modules, I append '.git' to the end.  You may also select the initial remote branch to check out, which will automatically create a duplicate local branch.

Screenshot - Git Repository Exploring Screenshot - Clone URI Screenshot - Clone Remote Branches Screenshot - Clone Destination Screenshot - New Repository

Creating a Workspace Project

You can import the projects by right clicking on the new repository.  You'll need to select the 'Import as General Project' option, and it is safe to not share new projects.  Leave the top level Working Directory selected and click next.  The next screen has the project name and path filled in and read-only, and after clicking next your new project will be available within your workspace.

Screenshot - Import Project in Git Repository Screenshot - Import Project Screenshot - Import Project Location

Creating Patches

One of the major limitations of EGit currently is that it only provides patches between successive commits[2].  Since it would be bad practice to not commit your progress changes, and a challenge to work on different tasks simultaneously without commiting, this will have to be worked around.

My current solution is to utilize a copy of the module checked out through CVS as well as the Git copy (to help keep them organized, use Working Sets). 

  1. Generate patches of each commit via the Git copy, and apply them in succession to the CVS copy.  You can then create a singular patch from the CVS copy's working copy changes.  This could get tedious if you have a lot of commit steps, are generating final patches for multiple branches, or keeping up with a frequently changing CVS HEAD.  An advantage is that if you are modifying multiple files for a branch, they will all be updated together.

    To create a patch you will have to open the History view, either by right clicking on your project and selecting Team -> Show in History or through Window -> Show View (History is with the Team category).  Each commit will be show in the History view, with the newest commits first.  For each commit you need a patch for, right click and select the Create Patch option.  You can either place the patch in the clipboard to paste elsewhere, or preferably save it as a file.  The default save path is generated from the commit's message, so you will likely want to change this value.  On the next page leave the "Export in Git format" checkbox empty.

    Screenshot - Open Project History View Screenshot - History View - Create Patch Screenshot - Patch - Select Location Screenshot - Patch - Select Type

  2. Copy changes from the Git project to the CVS project with the comparison editor.  This process will have to be repeated for each file with changes, but can apply multiple commits to the file in one step.

    Select the CVS and Git copies of the file in separate projects (with Ctrl+click) and select Compare with -> Each Other in the right-click contextual menu.  Any non-conflicting changes can be quickly copied over with the appropriate toolbar button, and then manually copy any remaining changes.

    Screenshot - Compare CVS and Git file to Each Other Screenshot - Comparison Editor

Updating Your Repository

You can update your local repository through a project's right-click menu, via Team -> Fetch From..., or via the Git Repository Exploring perspective by right clicking on the repository.  This will open a dialog, but just check that the remote repository selection has 'origin: git://git.drupal.org/project/...' selected and follow through till the end.  The default fetch configuration will be used unless you make any changes.

Screenshot - Project Perspective - Fetch Updates Screenshot - Git Repositories Perspective - Fetch Updates Screenshot - Fetch Updates - Remote Repository Screenshot - Fetch Updates - References

Alternately, through the Git Repository Exploring perspective you can right click the fetch configuration to perform the operation with the default configuration.

Screenshot - Git Repositories Perspective - Fetch Updates from Remote Config

Footnotes

[1] Another user in IRC noted that they were unable to clone from git.drupalcode.org, while git.drupal.org worked fine.  I was able to use both succesfully, but if you encounter issues while cloning it may help to try the other.

[2] There is mention of plans to implement features such as patches between a set of commits or your working copy, and a couple feature requests for such, but I'm not aware of current progress.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <br> <p>
  • Lines and paragraphs break automatically.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.