From fbb66bdb00b81fc817d9ecd4eed70d4e7d2b4a3e Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sun, 13 Sep 2015 19:19:51 +0200 Subject: [PATCH] Don't use IPath.equals() since it is broken on Windows C:\\test and c:\\test are different paths for IPath.equals(). So if we search for repositories, we cannot rely on it's implementation and should compare java.io.File instances instead. Bug: 475453 Change-Id: I9ec19dc3cc31b4717db5a6348cb84a9d4e7751ae Signed-off-by: Andrey Loskutov --- .../core/test/op/ConnectProviderOperationTest.java | 40 ++++++++++++++++++++++ .../egit/core/op/ConnectProviderOperation.java | 8 +++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java index 85fbafab6..11a536b2d 100644 --- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java +++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ConnectProviderOperationTest.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.egit.core.test.op; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -23,6 +25,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; @@ -36,6 +39,7 @@ import org.eclipse.egit.core.test.TestRepository; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.util.FS; import org.eclipse.team.core.RepositoryProvider; import org.junit.Assert; import org.junit.Test; @@ -74,6 +78,42 @@ public class ConnectProviderOperationTest extends GitTestCase { } @Test + public void testNewRepositoryCaseSensitive() + throws CoreException, IOException { + if (FS.detect().isCaseSensitive()) { + return; + } + Repository repository = FileRepositoryBuilder.create(gitDir); + repository.create(); + repository.close(); + + IPath path = new Path(gitDir.toString()); + String device = path.getDevice(); + if (device == null) { + // not windows??? + return; + } + if (!device.toLowerCase().equals(device)) { + path = path.setDevice(device.toLowerCase()); + } else { + path = path.setDevice(device.toUpperCase()); + } + assertNotEquals(path, new Path(gitDir.toString())); + assertNotEquals(path.toFile().toString(), + new Path(gitDir.toString()).toFile().toString()); + assertEquals(path.toFile(), gitDir); + + ConnectProviderOperation operation = new ConnectProviderOperation( + project.getProject(), + path.toFile()); + operation.execute(null); + + assertTrue(RepositoryProvider.isShared(project.getProject())); + + assertTrue(gitDir.exists()); + } + + @Test public void testAutoIgnoresDerivedFolder() throws Exception { // enable auto-ignore IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator 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 73b0a1351..6202f55a6 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 @@ -219,9 +219,13 @@ public class ConnectProviderOperation implements IEGitOperation { @Nullable private RepositoryMapping findActualRepository( Collection repos, File suggestedRepo) { - IPath path = Path.fromOSString(suggestedRepo.getPath()); + File path = Path.fromOSString(suggestedRepo.getPath()).toFile(); for (RepositoryMapping rm : repos) { - if (path.equals(rm.getGitDirAbsolutePath())) { + IPath other = rm.getGitDirAbsolutePath(); + if (other == null) { + continue; + } + if (path.equals(other.toFile())) { return rm; } } -- 2.11.4.GIT