Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2017-01-20 00:28:12 +0000
committerMatthias Sohn2017-02-01 22:46:41 +0000
commit57b32833c43dd4589d7178695edf4d66568f1213 (patch)
treeb5a7c1cf5f0390af9d122da6925bdeacb7f6c55c
parentf78ba98dbd3e9ebfee49c2c5dcc6f75e8062d97e (diff)
downloadegit-57b32833c43dd4589d7178695edf4d66568f1213.tar.gz
egit-57b32833c43dd4589d7178695edf4d66568f1213.tar.xz
egit-57b32833c43dd4589d7178695edf4d66568f1213.zip
Auto-ignore the .metadata and .recommenders folders in the workspace
Auto-ignore the .metadata and .recommenders folders in the workspace if the workspace root is located in a git repository's working tree (which is not recommended). Bug: 332834 Change-Id: Ied46005417810edd9312d5563c501f9999002068 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties1
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java53
4 files changed, 59 insertions, 1 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java
index f8e8595e1..b23f9c854 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/IgnoreOperationTest.java
@@ -133,7 +133,8 @@ public class IgnoreOperationTest extends GitTestCase {
File ignoreFile = new File(rootFile, Constants.GITIGNORE_FILENAME);
String content = testUtils.slurpAndClose(ignoreFile.toURI().toURL()
.openStream());
- assertEquals("/" + project.getProject().getName() + "/\n", content);
+ assertEquals("/.metadata/\n/" + project.getProject().getName() + "/\n",
+ content);
assertTrue(operation.isGitignoreOutsideWSChanged());
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
index b9f9833d1..aabf2f6d6 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/CoreText.java
@@ -77,6 +77,9 @@ public class CoreText extends NLS {
public static String ConfigureFetchAfterCloneTask_couldNotFetch;
/** */
+ public static String ConnectProviderOperation_autoIgnoreMetaData;
+
+ /** */
public static String ConnectProviderOperation_connecting;
/** */
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
index a6885d3c2..fb32848ad 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/coretext.properties
@@ -16,6 +16,7 @@ CherryPickOperation_cherryPicking=Running cherry-pick on commit {0}
CommitFileRevision_pathNotIn=Path {1} not in commit {0}.
CommitFileRevision_errorLookingUpPath=IO error looking up path {1} in {0}.
ConfigureFetchAfterCloneTask_couldNotFetch=Could not fetch with refSpec {0}
+ConnectProviderOperation_autoIgnoreMetaData=Auto-ignore .metadata and .recommenders if repository is located in Eclipse workspace
ConnectProviderOperation_connecting=Connecting Git team provider.
ConnectProviderOperation_ConnectingProject=Connecting project {0}
ConnectProviderOperation_ConnectErrors=Connecting Git team provider failed. See log for details.
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
index f1d250e98..b0ee64680 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -28,6 +29,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,14 +40,19 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.GitProvider;
+import org.eclipse.egit.core.JobFamilies;
+import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.core.internal.CoreText;
import org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry;
+import org.eclipse.egit.core.internal.job.JobUtil;
import org.eclipse.egit.core.internal.trace.GitTraceLocation;
import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryFinder;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.RepositoryProvider;
@@ -169,6 +176,8 @@ public class ConnectProviderOperation implements IEGitOperation {
}
autoIgnoreDerivedResources(project, subMon.newChild(10));
+ autoIgnoreWorkspaceMetaData(
+ actualMapping.getRepository().getDirectory().toPath());
}
/**
@@ -223,6 +232,50 @@ public class ConnectProviderOperation implements IEGitOperation {
}
}
+ /**
+ * Auto-ignore the .metadata and .recommenders folders located in the
+ * workspace root if the workspace is in the working tree of a git
+ * repository (which is not recommended)
+ *
+ * @param gitDir
+ * path of git directory containing the git repository
+ */
+ private static void autoIgnoreWorkspaceMetaData(java.nio.file.Path gitDir) {
+ java.nio.file.Path workspaceRoot = ResourcesPlugin.getWorkspace()
+ .getRoot().getLocation().toFile().toPath();
+ try (Repository r = FileRepositoryBuilder.create(gitDir.toFile())) {
+ if (!r.isBare()
+ && workspaceRoot.startsWith(r.getWorkTree().toPath())) {
+ Collection<IPath> ignoredPaths = buildIgnoredPathsList(
+ workspaceRoot, ".metadata", //$NON-NLS-1$
+ ".recommenders"); //$NON-NLS-1$
+ JobUtil.scheduleUserJob(new IgnoreOperation(ignoredPaths),
+ CoreText.ConnectProviderOperation_autoIgnoreMetaData,
+ JobFamilies.AUTO_IGNORE);
+ }
+ } catch (IOException e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ }
+
+ private static Collection<IPath> buildIgnoredPathsList(
+ java.nio.file.Path workspaceRoot,
+ String... metaDataDirectoryNames) {
+ Collection<IPath> ignoredPaths = new HashSet<IPath>();
+ for (String m : metaDataDirectoryNames) {
+ Path metaData = new Path(
+ workspaceRoot.resolve(m).toAbsolutePath().toString());
+ try {
+ if (RepositoryUtil.canBeAutoIgnored(metaData)) {
+ ignoredPaths.add(metaData);
+ }
+ } catch (IOException e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ }
+ return ignoredPaths;
+ }
+
private List<IPath> findDerivedResources(IContainer c)
throws CoreException {
List<IPath> derived = new ArrayList<IPath>();

Back to the top