|
12 | 12 | package org.eclipse.egit.ui.internal.repository.tree.command;
|
13 | 13 |
|
14 | 14 | import java.io.File;
|
| 15 | +import java.io.IOException; |
15 | 16 | import java.util.HashMap;
|
16 | 17 | import java.util.List;
|
17 | 18 | import java.util.Map;
|
|
40 | 41 | import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
|
41 | 42 | import org.eclipse.jface.window.Window;
|
42 | 43 | import org.eclipse.jface.wizard.WizardDialog;
|
| 44 | +import org.eclipse.jgit.lib.Repository; |
43 | 45 | import org.eclipse.jgit.util.FileUtils;
|
44 | 46 | import org.eclipse.team.core.RepositoryProvider;
|
45 | 47 |
|
@@ -71,26 +73,41 @@ private void addRepository(File repositoryDir) {
|
71 | 73 | }
|
72 | 74 |
|
73 | 75 | private void autoShareProjects(File repositoryDir) {
|
74 |
| - IPath workingDirPath = new Path(repositoryDir.getAbsolutePath()) |
75 |
| - .removeLastSegments(1); |
| 76 | + // Don't even try to auto-share for bare repositories. |
| 77 | + IPath workingDirPath; |
| 78 | + try { |
| 79 | + Repository repo = Activator.getDefault().getRepositoryCache() |
| 80 | + .lookupRepository(repositoryDir); |
| 81 | + if (repo.isBare()) { |
| 82 | + return; |
| 83 | + } |
| 84 | + workingDirPath = new Path(repo.getWorkTree().getAbsolutePath()); |
| 85 | + } catch (IOException e) { |
| 86 | + org.eclipse.egit.ui.Activator.logError(e.getLocalizedMessage(), e); |
| 87 | + return; |
| 88 | + } |
76 | 89 | Map<IProject, File> connections = new HashMap<>();
|
77 | 90 | IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
|
78 | 91 | .getProjects();
|
79 | 92 | for (IProject project : projects) {
|
| 93 | + // Skip closed projects |
| 94 | + if (!project.isAccessible()) { |
| 95 | + continue; |
| 96 | + } |
80 | 97 | RepositoryProvider provider = RepositoryProvider
|
81 | 98 | .getProvider(project);
|
82 |
| - if (provider != null) |
| 99 | + if (provider != null) { |
83 | 100 | continue;
|
84 |
| - |
| 101 | + } |
85 | 102 | IPath location = project.getLocation();
|
86 |
| - if (location == null) |
| 103 | + if (location == null) { |
87 | 104 | continue;
|
88 |
| - |
| 105 | + } |
89 | 106 | // In case the project is not inside the working directory, don't
|
90 | 107 | // even search for a mapping.
|
91 |
| - if (!workingDirPath.isPrefixOf(location)) |
| 108 | + if (!workingDirPath.isPrefixOf(location)) { |
92 | 109 | continue;
|
93 |
| - |
| 110 | + } |
94 | 111 | RepositoryFinder f = new RepositoryFinder(project);
|
95 | 112 | f.setFindInChildren(false);
|
96 | 113 | try {
|
|
0 commit comments