Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2013-10-03 16:58:24 +0000
committerRobin Stocker2013-12-07 15:25:17 +0000
commitdfabf79e4c01c381e84fd302001055de58b034c3 (patch)
tree6685032622c264a4d84ae0b40bdc70d9da86c1d5
parentdfeeb22b31ee4b6ae740635c1176d4e2e9f47a1c (diff)
downloadegit-dfabf79e4c01c381e84fd302001055de58b034c3.tar.gz
egit-dfabf79e4c01c381e84fd302001055de58b034c3.tar.xz
egit-dfabf79e4c01c381e84fd302001055de58b034c3.zip
Fix "overlaps the location of another project" when importing
Given the following: * Git repository containing a .project at the root of the repository * .project contains "foo" as project name * Repository is called "bar" on the server Do the following: 1. Start the Git import wizard 2. Clone the repository directly into the workspace (e.g. /home/ws and clone destination is /home/ws/bar) 3. Select "Import existing projects" 4. Finish Expected: The project is successfully imported Actual: Error "/home/ws/bar overlaps the location of another project: bar" This change fixes it by using the same logic as platform uses, see WizardProjectsImportPage.ProjectRecord. Bug: 327975 Change-Id: I23939def6d1a3b88a0812b53fee98a403a664c23 Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java37
1 files changed, 33 insertions, 4 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java
index d7c8e8ed70..4df2186304 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/ProjectRecord.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 IBM Corporation and others.
* Copyright (C) 2007, Martin Oberhuber (martin.oberhuber@windriver.com)
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
@@ -22,6 +22,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.NLS;
/**
@@ -43,9 +44,19 @@ public class ProjectRecord {
projectSystemFile = file;
IPath path = new Path(projectSystemFile.getPath());
try {
- description = ResourcesPlugin.getWorkspace()
- .loadProjectDescription(path);
- projectName = description.getName();
+ // If the file is in the default location, use the directory
+ // name as the project name. Otherwise we will get an error like
+ // "foo overlaps the location of another project foo" when importing
+ // in case the directory name and the name in .project do not match.
+ if (isDefaultLocation(path)) {
+ projectName = path.segment(path.segmentCount() - 2);
+ description = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(projectName);
+ } else {
+ description = ResourcesPlugin.getWorkspace()
+ .loadProjectDescription(path);
+ projectName = description.getName();
+ }
} catch (CoreException e) {
description = null;
projectName = path.lastSegment();
@@ -97,4 +108,22 @@ public class ProjectRecord {
public String toString() {
return projectName;
}
+
+ /**
+ * Returns whether the given project description file path is in the default
+ * location for a project
+ *
+ * @param path
+ * The path to examine
+ * @return Whether the given path is the default location for a project
+ */
+ private boolean isDefaultLocation(IPath path) {
+ // The project description file must at least be within the project,
+ // which is within the workspace location
+ if (path.segmentCount() < 2)
+ return false;
+ return path.removeLastSegments(2).toFile()
+ .equals(Platform.getLocation().toFile());
+ }
+
} \ No newline at end of file

Back to the top