Setting up My Eclipse / EGit for Drupal Development

This is work in progress...

I like working in Eclipse, and I've gotten used to having one project for each major Drupal version. This allows me to put the corresponding contribs inside the respective sites/all/modules directory and to just .gitignore them. That way I can let my local webserver serve each Drupal version without having to switch branches.

Set Up a Cache

First, to avoid repeated cloning over the network and wasting lots of disk space, I've set up my own cache of the Drupal repository according to Randy Fay's Reference (cache) repositories to speed up clones: git clone --reference blog post and the script that mfer wrote based on it: mfer's sandbox: Drupal Git Cache (requires mktemp as well as my patches in the queue).

Use EGit to Clone D5 into a New PHP Project

To get Eclise/EGit to set up the initial project structure, I tell it to clone the 5.x branch of git://git.drupal.org/project/drupal.git into a directory called d5. Besides the Drupal files and the .git directory, d5 contains the following three items, that turn it into an Eclipse project:
.settings/
.buildpath
.project

Create the Other Drupal Projects

Now I do something like
git clone --reference cache --branch 7.x -- git://git.drupal.org/project/drupal d7

This creates a repository for the Drupal 7 branch with a .git directory size of 200K (instead of 50MB for the uncached Drupal project).

After copying the three Eclipse/EGit items and adjusting them for the new project name, I can import the newly created project into the Eclipse workspace:
-- File|Import|Git|Projects from Git, [Add], [Browse], [Search], [OK]
-- [Next], Import Existing Projects & Share New Projects Interactively, [Next], select, [Next], [Finish]

I do this for D6 and D5, and, to .gitignore the Eclipse items, I do
git config --global core.excludesfile ~/.gitignore
and create a global C:/Users/HS/.gitignore file that lists the three Eclipse items.

Now we have three nice and clean Drupal projects.

Contrib Modules in sites/all/modules

Initially, I planned to try something like...
git submodule add --reference ../cache --branch 7.x-1.x -- ssh://salvis@git.drupal.org/project/acl sites/all/modules/acl

... but EGit does not support submodules. Also, from what I read in Pro Git, submodules may be more trouble than they're worth. Moreover, since these are my test sites, I'll probably download and install a number of other modules that I may or may not want to run under version control.

So, instead, I just add sites/ to ~/.gitignore and will put uncontrolled copies of the contribs into sites/all/modules.

Missing 7.x-1.x Branches

Since I've been developing against CVS HEAD, I have the master branch pointing to my latest commit, but I don't have any 7.x-1.x branch. I fixed this by doing
git clone --reference cache -- ssh://salvis@git.drupal.org/project/acl
cd acl
git push origin master:7.x-1.x
for each contrib module that I maintain. After that, I immediately deleted those repo clones; they contain all branches from d.o, and I want to have branch-specific repos. There are other ways to get the same result, but thanks to our cache, cloning is quick.

Maintained Contribs

Now I have projects and directories called d5 through d8, and I want to create projects and directories c5 through c7 (for now) at the same level to keep the contrib modules that I maintain. To keep the Eclipse project tree manageable, I would have liked to have projects like c7, which would contain the D7 versions of each contrib module. However, I've been unable to get Eclipse/EGit to accept having multiple repositories in one project.

The compromise for now is to have the intended structure in the file systems, but to create projects like c7-acl, which contain one branch-specific repo for one module:
git clone --reference ../cache --branch 7.x-1.x -- ssh://salvis@git.drupal.org/project/acl

In Eclipse we can then create the project with
File|New|PHP Project, c7-acl, Create project from existing source: ...\c7\acl, [Next], [Finish]
Then right-click on the newly created project node and
Team|Share Project, Git [Next], [Finish]

Finally copy all contribs from c7 to d7\sites\all\modules and remove the Git and Eclipse files and directories.

The End Result

I end up with a directory structure like

D:\PDev\Drupal\
  c5
    acl
    forum_access
  c6
    acl
    forum_access
  c7
    acl
    forum_access
  cache
  d5
    sites\all\modules
      acl
      forum_access
  d6
    sites\all\modules
      acl
      forum_access
  d7
    sites\all\modules
      acl
      forum_access
  d8

and a project structure in Eclipse like

D:\PDev\Drupal\
  c5-acl
  c5-FA
  c6-acl
  c6-FA
  c7-acl
  c7-FA
  cache
  d5
  d6
  d7
  d8

I do my development in the dX projects (which are webroots for my test sites). Due to EGit's lack of submodule support, I cannot put the contribs under dX/sites/all/modules under version control (at least not under EGit's control). This is not ideal, but it's similar to what I've been used to with CVS, so it's not too bad either.