6

I have a number of eclipse projects that I'd like to have in two separate hg repositories.

I've managed to do this by first creating the two hg repository using TortouiseHg and adding, committing my projects to each of the repositories first. By doing that I now have two hg repositories with two projects in each.

Next I clone that repositories in Eclipse using MercurialEclipse. The projects appear as expected in Eclipse.

Example 1:

Eclipse workspace
               |
               |--Project 1
               |--Project 2
               |--Project 3
               |--Project 4

But if I look in the directory structure it looks like this:

Example 2:

  c:-- 
     |
     |-workspace
               |
               hgRepository1
               |           |--.hg
               |           |--Project 1
               |           |--Project 2
               |
               |
               hgRepository2
                           |--.hg
                           |--Project 3
                           |--Project 4

when I want it to look like this.

Example 3:

  c:-- 
     |
     |-workspace
               |--.hg
               |--Project 1
               |--Project 2
               |--Project 3
               |--Project 4

Is it possible to have a single Mercurial repository and somehow clone it and have the projects appear directly under workspace directory, and not in a subdirectory?

stuff22
  • 1,662
  • 4
  • 24
  • 42
  • You can't make 1 .hg directory contain data from multiple repositories. Are those 4 projects really just parts of the same project, or are they different projects that you've combined in some way? – Lasse V. Karlsen Jan 21 '11 at 20:04
  • 1
    I might have not been clear....... but it's one hg repository containing multiple eclipse projects. They're not nested hg repositories. – stuff22 Jan 21 '11 at 20:54

4 Answers4

5

You shouldn't save project from an Eclipse workspace, or restore them in an Eclipse workspace.
Those projects (.project, .classpath, and other project specific resources) should be in their own directory, outside of the Eclipse workspace (and then imported into the workspace).

That way, any directory structure will be fine for importing the different project into a new Eclipse workspace.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Two issues, if I understand you correctly. Lets say I don't import/clone the mercurial repository into the workspace. I do it somewhere else and then import into eclipse. This still doesn't solve the fact that the projects themselves reside in different places in the directory tree. They will still show up looking like example 2 but obviously not in the workspace directory. – stuff22 Jan 21 '11 at 21:01
  • @stuff22: the idea is they can show up wherever they want: once the repo is cloned (with whatever internal structure it has to follow), you will always be able *then* to import said projects into Eclipse workspace. You don't have to follow any specific workspace structure for your projects. – VonC Jan 21 '11 at 21:43
3

I ran into this exact problem myself, and the solution isn't immediately obvious. This blog post has step-by-step instructions showing how to achieve what you're after: workflow: create and init multi-project repositories with HgEclipse (Mercurial).

In short, you want to:

  • Open the Mercurial View and create a new repository at /path/to/workspace/projects-folder
  • Create however many new projects you need, each one should be created at the (non-default) location of /path/to/workspace/projects-folder/project name.

You'll find you end up with the layout you want in Eclipse and the projects will all share the repository located in projects-folder.

akatkinson
  • 548
  • 4
  • 17
  • 1
    Thank you for the link. It actually works, and with latest HgEclipse it seems it's not needed to perform steps 2.2 and 2.3 as described in the original post. Just adding projects at non-default location under the same repository works out of the box. – Mikhail Sep 28 '13 at 11:36
1

I don't quite understand. You cannot clone the repo to inside of itself. Why can't you just make a hard copy of Project1 and Project2, creating 3 and 4?

Roberto
  • 11,557
  • 16
  • 54
  • 68
  • I'm not cloning the repositories inside themselves. The .hg just indicates which folders are the mercurial repositories (or where I'd like them to be) – stuff22 Jan 21 '11 at 20:55
  • I still dont get it. Why don't you make the structure that you want with 1 hg repo and import the existing projects into the eclipse workspace? – Roberto Jan 24 '11 at 19:19
  • anyways, I think what I'm trying to say is the samething VonC is saying. Do whatever structure you want to do and then import each project in eclipse. The .project, .classpath and other files will be inside your eclipse workspace (outside the hg repo) but you will be editing source files from your hg repo through eclipse. – Roberto Jan 24 '11 at 19:26
1

I know some people wont like my solution (and I know that it's been some time since this question has been asked) but here it is:

  1. Create the workspace as usual
  2. Exit from Eclipse (not sure if it is necessary but it doesn't harm to do it)
  3. Clone your Mercurial repository directly in the created workspace directory with hg (it helps if the name of your repository is the same as the workspace)
  4. Go back to Eclipse and create a new project for each sub-directory (in your example it would be Project 1, Project 2, etc.). It will warn you that the directory already exists but it's ok.
  5. MercurialEclipse should recognize each project as being Mercurial version controlled

This has been tested successfully in CDT in Eclipse on linux. And I advise you to put in your .hgignore the files created by Eclipse to manage your projects.

I hope this helps.

Evens F.
  • 11
  • 1