diff options
author | Matthias Sohn | 2016-03-17 13:40:53 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-03-17 13:40:55 +0000 |
commit | ab8cd06d5d50ecc7c1c97478121ddd219fd40e9a (patch) | |
tree | 0ddf7e068a889cc1df7c77714d6dc6fac467b61a | |
parent | a8bcee9ea7a58e6db797b86c735f0bdb9e774c18 (diff) | |
parent | 241d23eb7313644e8b4a428f88724336e48374f4 (diff) | |
download | egit-ab8cd06d5d50ecc7c1c97478121ddd219fd40e9a.tar.gz egit-ab8cd06d5d50ecc7c1c97478121ddd219fd40e9a.tar.xz egit-ab8cd06d5d50ecc7c1c97478121ddd219fd40e9a.zip |
Merge "Handle submodules in auto-sharing"
3 files changed, 36 insertions, 15 deletions
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java index 47fedba552..8eb51d2642 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -499,12 +500,12 @@ public class Activator extends Plugin implements DebugOptionsListener { } RepositoryFinder f = new RepositoryFinder(project); f.setFindInChildren(false); - Collection<RepositoryMapping> mappings = f.find(new NullProgressMonitor()); - if (mappings.size() != 1) { + List<RepositoryMapping> mappings = f + .find(new NullProgressMonitor()); + if (mappings.isEmpty()) { return; } - - RepositoryMapping m = mappings.iterator().next(); + RepositoryMapping m = mappings.get(0); IPath gitDirPath = m.getGitDirAbsolutePath(); if (gitDirPath == null || gitDirPath.segmentCount() == 0) { return; @@ -526,9 +527,21 @@ public class Activator extends Plugin implements DebugOptionsListener { } // connect - final File repositoryDir = gitDirPath.toFile(); + File repositoryDir = gitDirPath.toFile(); projects.put(project, repositoryDir); + // If we had more than one mapping: add the last one as + // 'configured' repository. We don't want to add submodules, + // that would only lead to problems when a configured repository + // is deleted. + int nofMappings = mappings.size(); + if (nofMappings > 1) { + IPath lastPath = mappings.get(nofMappings - 1) + .getGitDirAbsolutePath(); + if (lastPath != null) { + repositoryDir = lastPath.toFile(); + } + } try { Activator.getDefault().getRepositoryUtil() .addConfiguredRepository(repositoryDir); 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 6b6406fea3..87b698143b 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 @@ -16,8 +16,8 @@ package org.eclipse.egit.core.project; import java.io.File; import java.util.ArrayList; -import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.eclipse.core.resources.IContainer; @@ -55,7 +55,7 @@ import org.eclipse.jgit.util.SystemReader; public class RepositoryFinder { private final IProject proj; - private final Collection<RepositoryMapping> results = new ArrayList<RepositoryMapping>(); + private final List<RepositoryMapping> results = new ArrayList<RepositoryMapping>(); private final Set<File> gitdirs = new HashSet<File>(); private final Set<File> ceilingDirectories = new HashSet<File>(); @@ -95,12 +95,13 @@ public class RepositoryFinder { * @param m * a progress monitor to report feedback to; may be null. * @return all found {@link RepositoryMapping} instances associated with the - * project supplied to this instance's constructor. + * project supplied to this instance's constructor, in the order + * they were found. * @throws CoreException * Eclipse was unable to access its workspace, and threw up on * us. We're throwing it back at the caller. */ - public Collection<RepositoryMapping> find(IProgressMonitor m) + public List<RepositoryMapping> find(IProgressMonitor m) throws CoreException { return find(m, false); } @@ -113,13 +114,15 @@ public class RepositoryFinder { * @param searchLinkedFolders * specify if linked folders should be included in the search * @return all found {@link RepositoryMapping} instances associated with the - * project supplied to this instance's constructor. + * project supplied to this instance's constructor, in the order + * they were found. * @throws CoreException * Eclipse was unable to access its workspace, and threw up on * us. We're throwing it back at the caller. * @since 2.3 */ - public Collection<RepositoryMapping> find(IProgressMonitor m, boolean searchLinkedFolders) + public List<RepositoryMapping> find(IProgressMonitor m, + boolean searchLinkedFolders) throws CoreException { find(m, proj, searchLinkedFolders); return results; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/AddCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/AddCommand.java index c0aed4086b..4eb3f75f6a 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/AddCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/AddCommand.java @@ -12,8 +12,8 @@ package org.eclipse.egit.ui.internal.repository.tree.command; import java.io.File; -import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.core.commands.ExecutionEvent; @@ -91,10 +91,15 @@ public class AddCommand extends RepositoryFinder f = new RepositoryFinder(project); f.setFindInChildren(false); try { - Collection<RepositoryMapping> mappings = f + List<RepositoryMapping> mappings = f .find(new NullProgressMonitor()); - if (mappings.size() == 1) - connections.put(project, repositoryDir); + if (!mappings.isEmpty()) { + // Connect to the first one; it's the innermost. + IPath gitDir = mappings.get(0).getGitDirAbsolutePath(); + if (gitDir != null) { + connections.put(project, gitDir.toFile()); + } + } } catch (CoreException e) { // Ignore this project in that case continue; |