Skip to content

Commit 275ec28

Browse files
author
Thomas Wolf
committed
Don't auto-share for closed projects or for bare repositories
For bare repositories, there's no working directory, and thus there cannot be anything to share. And closed projects cannot be auto-shared since one cannot get or set session properties. Change-Id: Id3e054fc2bda94df03e1243093a8a5c250be2190 Signed-off-by: Thomas Wolf <[email protected]>
1 parent c2daf53 commit 275ec28

File tree

1 file changed

+25
-8
lines changed
  • org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command

1 file changed

+25
-8
lines changed

org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/AddCommand.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package org.eclipse.egit.ui.internal.repository.tree.command;
1313

1414
import java.io.File;
15+
import java.io.IOException;
1516
import java.util.HashMap;
1617
import java.util.List;
1718
import java.util.Map;
@@ -40,6 +41,7 @@
4041
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
4142
import org.eclipse.jface.window.Window;
4243
import org.eclipse.jface.wizard.WizardDialog;
44+
import org.eclipse.jgit.lib.Repository;
4345
import org.eclipse.jgit.util.FileUtils;
4446
import org.eclipse.team.core.RepositoryProvider;
4547

@@ -71,26 +73,41 @@ private void addRepository(File repositoryDir) {
7173
}
7274

7375
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+
}
7689
Map<IProject, File> connections = new HashMap<>();
7790
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
7891
.getProjects();
7992
for (IProject project : projects) {
93+
// Skip closed projects
94+
if (!project.isAccessible()) {
95+
continue;
96+
}
8097
RepositoryProvider provider = RepositoryProvider
8198
.getProvider(project);
82-
if (provider != null)
99+
if (provider != null) {
83100
continue;
84-
101+
}
85102
IPath location = project.getLocation();
86-
if (location == null)
103+
if (location == null) {
87104
continue;
88-
105+
}
89106
// In case the project is not inside the working directory, don't
90107
// even search for a mapping.
91-
if (!workingDirPath.isPrefixOf(location))
108+
if (!workingDirPath.isPrefixOf(location)) {
92109
continue;
93-
110+
}
94111
RepositoryFinder f = new RepositoryFinder(project);
95112
f.setFindInChildren(false);
96113
try {

0 commit comments

Comments
 (0)