Target location for project " " already exists, can not move project - eclipse

when I am trying to share my project with git repository getting exception like this
"Target location for project " " already exists, can not move project"

Writing an answer because I tried many options suggested in many similar questions but none worked. Then I did it manually with following steps that worked, and these steps will work for any Eclipse version:
Goto the Eclipse workspace in the file system and copy the project from there and paste it in some other location in your file system. This will serve as a backup.
Goto your Eclipse and then right click on the project and click delete. You can say delete from the file system because you've already taken a backup in step1.
Goto your Git repo in the file system and paste the project folder at the location you want (may be inside another folder with .project file doesn't matter).
Then come back to your Eclipse and then File->Import -> Import from Git -> Local repo -> Select the Git local repo where you've pasted the project in step 3 and then import it as usual.
As I said earlier, this will work for any Eclipse version.

This situation will happen if you already have a Project of the same name in your local git repository. Sharing a project means steps to commit your project into your local git repository and from there it as ORIGIN will be pushed to Master (Remote). (You are creating again with a new eclipse IDE, or that project was deleted from IDE but committed to local repository in the past).
Solution is simple:
Remove the project from your local git repository.
C:\Users\username\git on windows operating system. (If this not possible then next step)
Rename the project in your IDE (Better recreate a project with same code but with new Project name) that you want to share: repeat the process of sharing on Eclipse IDE.
You may optionally want to recreate after dropping the remote repository(master), if something is already pushed from last push of project, so that everything is clean. You may visit the git repository to confirm it.

In my case this was caused by an extraneous .project and related Eclipse files at the top of the git repository folder. The files were created by Eclipse due to incorrect folder specified on Import of the other projects in the repo.

Related

Start using Eclipse GIT with an existing project ... project files get moved

Yesterday I wanted to start using Eclipse eGIT on an existing project following the instructions on http://www.vogella.com/articles/EGit/article.html
This tutorial suggests to have the git repository outside of the workspace, and I followed this suggestion.
After the step "5.5. Using the Git Staging view for the initial commit" I committed my initial commit. Then I continued editing one of my source files that was still open. But when I tried to save my changes, Eclipse complained that the source file was no longer there.
Then I checked both my workspace and git folder, and the project files were only in git. This is mentioned nowhere in the tutorial. Is this normal behavior?
Even more surprising: In order to continue working normally with my already open files, I copied the project subfolder from .git back to the workspace folder. And now everything seems to be fine. My changes are reflected in workspace folder as well as in "Unstaged Changes" in the Git Staging view and in git folder.
Is this expected behavior?
I found out that the files really get moved. I needed to close all the open project files and then open them from package explorer again (which will open the files from git repository).

How to move Egit repository and working directory

I am new to Egit and created a new repository for a GWT project I'm working on. Unfortunately, I let it create the repository under my Dropbox folder, and now I'm regretting it because I'm syncing megabytes of temp files (e.g. *.class) over the internet. The "create repository" wizard also moved the project's files from the Eclipse workspace to a working directory under Dropbox (along with the .git folder).
What is an easy way for me to move this Egit repository and working directory to somewhere else, other than the Dropbox folder?
(btw, since I'm using Egit, the solution needs to work such that Eclipse is happy and I can keep building/using my project).
I managed to do it myself, here's how:
In Eclipse, right-click MyApp project, Refactor->Move. Move the Eclipse project to a new spot on disk. Note that I kept the .../GitRepositories/MyApp/MyApp dir structure, it's just that I moved the location of GitRepositories to a new place. Also note that this left the old dir with nothing but the .git folder inside it (i.e. Eclipse moved the working files/dirs but not the repo).
Close Eclipse
Move the .git directory from the old directory to the new. Be sure to keep it in the right relative place! I accidentally moved .git from .../GitRepositories/MyApp to .../GitRepositories/MyApp/MyApp. This screwed things up and I had to back track...
Start Eclipse
It might already work at this point, but because I moved .git to the wrong place when I first did it, I had to do the following steps:
Right-click MyApp project, Team->Disconnect
Right-click MyApp project, Team->Share Project...
The wizard automatically finds the Git report relative to the project dir: ../.git
Happy hacking...
When working with a local repository, you can just do the following:
Close Eclipse
Move the git repository on disk
Reopen Eclipse
Select File->Import... -> Git -> Projects from Git
Select local repository and add the new repository location
Select your project(s) to be added
(Optional) Remove the old project references from your workspace.
It may seem like a lot of steps, but it's actually very simple and less invasive than moving the repo and working copy separately.

How to create Eclipse project with EGit clone

After spending a decade with SVN I've finally taken the plunge with Git. I have set up Git, Gitolite and GitLab on a server and have successfully added code to my local repository, committed, cloned repositories and pushed code back to repositories. So far, so good. Now enters EGit...
I have cloned a repository using the Git Repository Exploring view using the following syntax for the path:
ssh://dexter:vaultanalyser.git
(In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project? Rather than a SVN-style single parent repository that contains multiple projects?)
This imports the repository into:
/Users/mattpainter/git/vaultanalyser
I was expecting this step to automatically create an Eclipse project for me with all the source, but this isn't so. I tried fudging the target directory so it's in my workspace, but this isn't working either.
How do I get the cloned source available within Eclipse? This site implies that if you create a project with the same name as the repository, it all magically works, but this isn't the case (yes, I know the article is about Github, not GitLab, but I figured the two were close enough for the task at hand).
I've then tried creating a project in Eclipse and sharing it - but then the whole project appears as a sub-folder in the repository. If repositories are indeed analogous to projects, this isn't really what I want.
I've looked through other StackOverflow topics that look related, but I fear I'm still missing a key piece of understanding with how this is supposed to work and it's all looking remarkably convoluted thus far.
Help?
In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project?
Yes, but a GitLab "project" isn't necessarily an Eclipse one.
It doesn't have to follow an SVN structure, as illustrated in "Eclipse reference directory outside eclipse project directory but within repository".
All you need to do is to create an Eclipse project, specifying the source directory being not in the default path (Eclipse workspace), but wherever you cloned your repo (as described in "Getting started with Eclipse + EGit - confused").
That way, the eclipse project you just declared (and referenced in the Eclipse workspace) has its files (.project and .classpath) at the root of the Git repo.
And Egit can then manage that project just fine.
Or you can import it directly with Egit: "Eclipse + EGit: clone project into workspace".
As the OP nullpainter reports below:
The original issue was compounded by invalid permissions in the .git/objects folder on the server.
Running a chmod git:git -R * on the folder solved the issue
He details the right setup below.
To expand on #VonC's answer, the steps to get EGit and Eclipse to play nicely is:
Select 'Clone a Git repository' from EGit, accepting all defaults. This will create a folder in a git parent folder, somewhere outside your workspace.
Create a new Eclipse project. I'm using Java, but I assume there are similar steps for other languages. On the first dialog, untick 'Use default location' and instead select the repository folder created in step 1. Accept all defaults.
Select Team > Share Project... from your new project. Select Git, and tick the 'Use or create repository in parent folder of project'.
Now you can push your code and Eclipse dot files to your git repository from within Eclipse.
(My original issue was compounded by invalid permissions in the .git/objects folder on the server - running a chmod git:git -R * on the folder solved the issues)
I check it out with the command line - then build my projects on top of that. In fact, I end up doing most operations with command line git. EGit is useful for viewing the diffs but I find command line has more power and control. Git is mostly about giving devs lots of power and control.

Eclipse + EGit: clone project into workspace

I'm a little confused about how EGit workes.
I have an existing git repository on Github and want to clone it into my workspace.
My goal is to have the local repository directly stored inside my workspace-folder but I don't get it working with EGit.
When I want to clone the github repo with EGit, I have to choose a directory as destination. The suggested directory is in my homedir (not in my workspace). When I choose this directory I can see the project in Eclipse but it is not stored in my workspace-folder. Instead it is stored in my home dir.
When I choose a directory directly inside my workspace, later when it comes to import the project it says that there is already a directory with this name.
I don't know how to solve this. I thought this would be a common scenario. In the past I have used hgEclipse (Mercurial) and it was working exactly the way I thought it should be so I'm confused EGit doesn't. Maybe I misunderstood something.
Probably this is important to know: In the github repository there are no .project or .settings files from eclipse. I have them on my .gitignore and so in the import-dialog I have to choose "Import as General Project" and not "Import Existing Projects". But I think this shouldn't matter?
I hope someone can help me or explain me why the EGit plugin doesn't clone the repository directly into the workspace by default.
My Eclipseversion is 3.6, I have installed EGit over the markedplace.
As mentioned in this EGit tutorial, the destination directory you mention when importing (cloning) a Git repo is any directory you want, in which the .git will be created:
You don't have to select the workspace itself (at least, you should select the workspace/myproject subdirectory, in order to not make the all Eclipse workspace a Git repo.
And you can select any other directory outside the workspace: the Eclipse workspace should only contain meta-data about Eclipse projects and settings.
When declaring a new project, you will be able to select the project directory, making that directory the parent for .classpath and .project.
Your workspace will list that new project, even though it lives outside the workspace.
To import a project from GitHub you should use the Import Git Repository as New Project dialogue (right click -> Import -> Git -> Git Repository as New Project). This way you can select the destination of the clone repository, including the Workspace.
If you want to edit the sources in the IDE and also want the changes to be reflected in the Git repository, delete the original source file in the project and link the source file in the git repo to the project. That way, you can directly make changes to the git repo and you can commit them when needed. Be careful not to delete the files when deleting the project in the IDE though.
Steps to have git project in workspace (with egit):
On GIT perspective choose "Clone a Git Repository and add it to this view"
As a destination choose folder inside a workspace (for example ".../workspace/myproject")
Wait until cloned
File -> New -> Project
General -> project
As a project name type name of a folder in workspace where project has been cloned (for example "myproject")
Nope. There's no way to get this to work. You can't use egit to checkout a git project into the workspace and if you check it out elsewhere and try to copy it into the workspace, you will lose your connection to the remote repository. If you want VCS that works, use svn or mercurial.
In the "Configure Local Storage Location" dialog,
choose .../workspace/projectname.
Then in the next dialog,
we get the wizard selection menu. Normally you should select "Import existing project".
(But see below).
Finally, there is the "Import Projects" dialog.
For various unexplained reasons, sometimes this dialog is empty and won't
let you finish. In that case, you need to cancel, and then outside of Eclipse completely delete the working directory that was cloned into, and then start again.
But if there is the project there, press finish. If it complains about the project already existing, go back to the wizard menu and change it to use a wizard. Select a Java wizard and then finish. Often this will work, but only if you first got the "Import Projects" menu to recognize the project in the first place.
It may take several attempts to get this to work! But once it is set up, it works fine.
So, in summary: is is possible to get EGit to use the default project location for the git clone, but in my experience it may inexplicably require several attempts.

Opening existing project from source control

I've been pushing my source to a Mercurial repository. Today I needed to delete my local copy and re-clone. I did this by simply moving my local copy somewhere else (just in case) and typing "hg clone url".
This part has worked just fine.
However, when I try to pull the newly cloned local copy into Eclipse, I get the following error:
/Users/Andrew/Dev/Workspace/Android/MyProject overlaps the location of another project: 'MyProject'
My guess is that I have been committing some meta file or something that I shouldn't have. Does anyone have any ideas? Here is my .hgignore:
syntax: regexp
\.DS_Store
.swo
.swp
.metadata/
/bin/
Note: Looks like my hgignore is not blocking the gen folder. Could this be part of the problem?
There is a bug in Eclipse what won't let you create an Android project from existing sources:
http://code.google.com/p/android/issues/detail?id=8431
You have to move MyProject to a folder that doesn't have any other projects in its sub-directories. You can then make a new project from existing source with MyProject. Remove the new project from the workspace without deleting the contents on disk and move it back to your Android folder. Now do an Import -> General -> Existing Project into Workspace, and MyProject should be available to import.
This is the only way I've been able to do it.
Ok, I'll try to sum it up, after I faced similar problems and wasted some time:
Eclipse Juno /4.2 SR1
(however I think it is a general misunderstanding of how eclipse imports projects)
If you want your new project "connected" to git/mercurial, you'll have to clone and import via "Import/Git/Import from Git"
It will fail if your "workspace dir" equals the "local destination dir".
A git clone via egit MUST NOT be placed! in the "eclipse workspace dir"!
The project import will fail because the projectname in the cloned ".project file" already exists in the eclipse workspace dir when the import occurs.
I think the problem is that you moved your local copy away and then you try to add another project into Eclipse at the same location as what you had before and you are just confusing Eclipse...
I would recommend to try to use command line commands for Mercurial and when you get into Eclipse, first clean up existing projects before adding another one.
My sollution was just to import as general project not an android one.
I ran into this problem when trying to import a git repo project and it's submodules. I ended up using import -> git -> Projects from Git (git plugin). This understood the concept of a project within a project just fine. The project is now monitored by that plugin. It's a good enough tradeoff for me.