I have an existing eclipse project that is a git repository, and am trying to use EGit with it. I started by selecting View->Other->Git->Git Repositories. This works fine, I can see the repo, and my branches, etc. Then, I attempt to select the Project, then Team->Share Project->Git, it sees a repository if I leave "Use or create repository in parent folder of project checked. When I click "Finish", I get the following error:

Thanks. I looked in the error log (didn't know there was one at the time I posted). It said that the "<my source dir> is not a valid location because the project contains a linked resource at that location". Which is true, because I have an "out of source" build as cmake recommends. My build looks like this.

So the I already have a project file, generated by cmake, and also already have a .git repository. I was just starting to use EGit and wanted to integrate with it.

If I use "Import existing projects", on my git repository, it complains because it can't find the .project file "No existing projects".

Must my .git directory be in the same place or above my .project file? This seems a little constraining, as keeping your build files out of source is fairly popular, and makes using .git easier, as I don't have to .gitignore everything.

In the structure you describe, sourceDir is a Git repository with no Eclipse projects and buildDir is an Eclipse project not part of any Git repository. That's pretty odd. I also don't understand why you want the Eclipse .project file in the buildDir rather than at the top of the tree.

I would think you would want a structure like this:

topLevelDir/
.git/
.project
.gitignore
sourceDir/
buildDir/

where .gitignore includes "buildDir/" (and whatever else you want to ignore)

Even better, consider adding an extra directory level for the current project to allow yourself the option of adding more projects to this repository later:

You can do it like that, use of cmake encourages out-of-source builds. The build files don't clutter up the source tree, and you don't have to ignore it, since Git isn't even aware of it, or clean it up when you're done. Just another way of doing things. Also, we don't commit our .project files, they're generated, with our make files when we run cmake. The only thing we move into our CM repository is the source, cmake files and .gitignore(s). We have several collaborative projects, each cloned of a different repository. Each containing it's own .git directory. So, we wouldn't use the project level.

I guess I am coming from the opposite direction. Why does EGit care about the relative location of the repository and .project files? Since cmake is used quite a bit, integrates well with Eclipse, it would seem as though EGit should support this paradigm. But, there may be good reasons why not.

As far as I know the EGit auto-importer is looking at the Git repository's working directory for .project files. Where else could it look? As I recall the SVN and CVS auto-importers behave the same way. So the reason the EGit importer says "no existing projects" is because there aren't any that it can see -- you've explicitly put the .project file somewhere else.

Conversely, you can manually import the .project in topLevelDir/buildDir, but since buildDir is not under version control, again by your explicit design, it won't be treated as an EGit project.

In short the behavior you report is exactly what I would expect.

Fwiw I've configured Eclipse C++ projects as I described earlier and it works fine, including EGit linkage, and with no "clutter". But I was not using cmake.

ps:

I don't know how you're using Eclipse here, but if you're treating the sources as just a tree of files, with no Eclipse builders, you can define a trivial .project in topLevelDir/sourceDir to do that and then commit it. This will give all developers EGIt access to your source tree.

R Shapiro skrev 2012-09-23 23.00:
> As far as I know the EGit auto-importer is looking at the Git repository's working directory for .project files. Where else could it look? As I recall the SVN and CVS
> auto-importers behave the same way. So the reason the EGit importer says "no existing projects" is because there aren't any that it can see -- you've explicitly put the
> .project file somewhere else.
>
> Conversely, you can manually import the .project in topLevelDir/buildDir, but since buildDir is not under version control, again by your explicit design, it won't be
> treated as an EGit project.
>
> In short the behavior you report is exactly what I would expect.
>
> Fwiw I've configured Eclipse C++ projects as I described earlier and it works fine, including EGit linkage, and with no "clutter". But I was not using cmake.

There are some thoughts about connecting containers (directories) at any level, but it's nowhere consistently done. This is kind of exotic, but I see the point
and it should be possible, though I'm not any team provider does it. Now we just someone willing to invest in this.