diff options
author | Robin Stocker | 2013-12-09 23:19:59 +0000 |
---|---|---|
committer | Matthias Sohn | 2013-12-15 22:27:01 +0000 |
commit | 83511314eb5f79ab3b5b2ab1923b6fead07c12d3 (patch) | |
tree | 514c9703bae96de79941235fa8eb35ce06ff74e1 | |
parent | 667a055b385ab309bfbaac2afec9779a808ba359 (diff) | |
download | egit-83511314eb5f79ab3b5b2ab1923b6fead07c12d3.tar.gz egit-83511314eb5f79ab3b5b2ab1923b6fead07c12d3.tar.xz egit-83511314eb5f79ab3b5b2ab1923b6fead07c12d3.zip |
Fix importing of submodule repositories using Git 1.7.8 layout
The submodule Git directory is in .git/modules/$mod and the .git in the
submodule directory is a text file with "gitdir: ../.git/modules/$mod".
This change includes three parts:
* Use FileRepositoryBuilder in RepositoryFinder to find repos, because
it already knows how to handle the above format
* Fix GitProjectData to handle RepositoryMapping where getGitDirPath
returns an absolute path (IPath#append just ignores that)
* Fix ExistingOrNewPage to be able to handle absolute paths where the
Git directory is not below the worktree path
FileRepositoryBuilder from JGit does not try to find a repository inside
GIT_CEILING_DIRECTORIES (like C Git does, see [1]), whereas EGit did
include the ceiling directories themselves. This change in behavior
required adjusting the test setup to set the ceiling to the parent dir.
[1] http://git-scm.com/docs/git#_the_git_repository
Bug: 378611
Change-Id: Iecf1c85f4d24b153ac734b3bd615e72fdfcb3717
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 files changed, 44 insertions, 50 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java index 1402c2673d..b163a05182 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/GitMoveDeleteHookTest.java @@ -76,7 +76,7 @@ public class GitMoveDeleteHookTest { SystemReader.setInstance(mockSystemReader); mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() - .getAbsoluteFile().toString()); + .getParentFile().getAbsoluteFile().toString()); workspaceSupplement = testUtils.createTempDir("wssupplement"); testDirs.add(testUtils.getBaseTempDir()); workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getAbsoluteFile(); diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java index d8ee426ad3..e2f22369f9 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitTestCase.java @@ -58,7 +58,7 @@ public abstract class GitTestCase { SystemReader.setInstance(mockSystemReader); mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() - .getAbsoluteFile().toString()); + .getParentFile().getAbsoluteFile().toString()); project = new TestProject(true); gitDir = new File(project.getProject().getWorkspace().getRoot() .getRawLocation().toFile(), Constants.DOT_GIT); diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java index a72e08deac..5ad2ba451b 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/GitProjectData.java @@ -492,7 +492,7 @@ public class GitProjectData { } m.setContainer(c); - git = c.getLocation().append(m.getGitDirPath()).toFile(); + git = m.getGitDirAbsolutePath().toFile(); if (!git.isDirectory() || !new File(git, "config").isFile()) { //$NON-NLS-1$ logAndUnmapGoneMappedResource(m); return; diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryFinder.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryFinder.java index 7dc550f82c..2d44413ffb 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryFinder.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/project/RepositoryFinder.java @@ -14,7 +14,6 @@ package org.eclipse.egit.core.project; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -30,8 +29,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.egit.core.internal.CoreText; import org.eclipse.egit.core.internal.trace.GitTraceLocation; import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.RepositoryCache.FileKey; -import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.util.SystemReader; /** @@ -57,7 +55,7 @@ public class RepositoryFinder { private final Collection<RepositoryMapping> results = new ArrayList<RepositoryMapping>(); private final Set<File> gitdirs = new HashSet<File>(); - private Set<String> ceilingDirectories = new HashSet<String>(); + private Set<File> ceilingDirectories = new HashSet<File>(); /** * Create a new finder to locate Git repositories for a project. @@ -71,8 +69,8 @@ public class RepositoryFinder { String ceilingDirectoriesVar = SystemReader.getInstance().getenv( Constants.GIT_CEILING_DIRECTORIES_KEY); if (ceilingDirectoriesVar != null) { - ceilingDirectories.addAll(Arrays.asList(ceilingDirectoriesVar - .split(File.pathSeparator))); + for (String path : ceilingDirectoriesVar.split(File.pathSeparator)) + ceilingDirectories.add(new File(path)); } } @@ -129,37 +127,14 @@ public class RepositoryFinder { if (loc != null) { final File fsLoc = loc.toFile(); assert fsLoc.isAbsolute(); - final File ownCfg = configFor(fsLoc); - final IResource[] children; - final FS fs = FS.detect(); - if (ownCfg.isFile() - && FileKey.isGitRepository(ownCfg.getParentFile(), fs)) { - register(c, ownCfg.getParentFile()); - } - if (c instanceof IProject) { - File p = fsLoc.getParentFile(); - while (p != null) { - // TODO is this the right location? - if (GitTraceLocation.CORE.isActive()) - GitTraceLocation.getTrace().trace( - GitTraceLocation.CORE.getLocation(), - "Looking at candidate dir: " //$NON-NLS-1$ - + p); - final File pCfg = configFor(p); - if (pCfg.isFile() - && FileKey.isGitRepository( - pCfg.getParentFile(), fs)) { - register(c, pCfg.getParentFile()); - } - if (ceilingDirectories.contains(p.getPath())) - break; - p = p.getParentFile(); - } - } + if (c instanceof IProject) + findInDirectoryAndParents(c, fsLoc); + else + findInDirectory(c, fsLoc); m.worked(1); - children = c.members(); + final IResource[] children = c.members(); if (children != null && children.length > 0) { final int scale = 100 / children.length; for (int k = 0; k < children.length; k++) { @@ -179,9 +154,30 @@ public class RepositoryFinder { } } - private File configFor(final File fsLoc) { - return new File(new File(fsLoc, Constants.DOT_GIT), - "config"); //$NON-NLS-1$ + private void findInDirectoryAndParents(IContainer container, File startPath) { + File path = startPath; + while (path != null && !ceilingDirectories.contains(path)) { + findInDirectory(container, path); + path = path.getParentFile(); + } + } + + private void findInDirectory(final IContainer container, + final File path) { + if (GitTraceLocation.CORE.isActive()) + GitTraceLocation.getTrace().trace( + GitTraceLocation.CORE.getLocation(), + "Looking at candidate dir: " //$NON-NLS-1$ + + path); + + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + File parent = path.getParentFile(); + if (parent != null) + builder.addCeilingDirectory(parent); + builder.findGitDir(path); + File gitDir = builder.getGitDir(); + if (gitDir != null) + register(container, gitDir); } private void register(final IContainer c, final File gitdir) { diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java index af9fe440e8..6d6fa776f7 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java @@ -78,7 +78,7 @@ public class SharingWizardTest extends LocalRepositoryTestCase { SystemReader.setInstance(mockSystemReader); mockSystemReader.setProperty(Constants.GIT_CEILING_DIRECTORIES_KEY, ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile() - .getAbsoluteFile().toString()); + .getParentFile().getAbsoluteFile().toString()); TestUtil.showExplorerView(); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java index 320e03e7f4..0d192d0b6e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java @@ -337,8 +337,8 @@ class ExistingOrNewPage extends WizardPage { updateProjectTreeItem(treeItem, project); treeItem.setText(1, project.getLocation().toOSString()); fillTreeItemWithGitDirectory(m, treeItem, false); - treeItem.setData(new ProjectAndRepo(project, treeItem - .getText(2))); + treeItem.setData(new ProjectAndRepo(project, m + .getGitDirAbsolutePath().toOSString())); treeItem.setChecked(true); } @@ -351,15 +351,16 @@ class ExistingOrNewPage extends WizardPage { TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE); updateProjectTreeItem(treeItem2, project); fillTreeItemWithGitDirectory(m, treeItem2, true); - treeItem2.setData(new ProjectAndRepo(project, treeItem2 - .getText(2))); + treeItem2.setData(new ProjectAndRepo(project, m + .getGitDirAbsolutePath().toOSString())); while (mi.hasNext()) { // fill in additional mappings m = mi.next(); treeItem2 = new TreeItem(treeItem, SWT.NONE); updateProjectTreeItem(treeItem2, project); fillTreeItemWithGitDirectory(m, treeItem2, true); treeItem2.setData(new ProjectAndRepo(m.getContainer() - .getProject(), treeItem2.getText(2))); + .getProject(), m.getGitDirAbsolutePath() + .toOSString())); } treeItem.setExpanded(true); allProjectsInExistingRepos = false; @@ -499,10 +500,7 @@ class ExistingOrNewPage extends WizardPage { treeItem.setText(2, UIText.ExistingOrNewPage_SymbolicValueEmptyMapping); else { - IPath container = m.getContainerPath(); - if (!container.isEmpty()) - container = Path.fromOSString("."); //$NON-NLS-1$ - IPath relativePath = container.append(m.getGitDir()); + IPath relativePath = new Path(m.getGitDir()); if (isAlternative) { IPath withoutLastSegment = relativePath.removeLastSegments(1); IPath path; |