Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2010-07-29 15:04:54 -0400
committerChris Aniszczyk2010-08-05 15:29:01 -0400
commit986e3823e1e3555bda426b3b09bd790d4595113a (patch)
treef6bc423e63d485003eb3f8bfc30243b96956675b /org.eclipse.egit.core.test
parent9d4a7f54b6d40ff2c523bc817e4cc57ff6def47d (diff)
downloadegit-986e3823e1e3555bda426b3b09bd790d4595113a.tar.gz
egit-986e3823e1e3555bda426b3b09bd790d4595113a.tar.xz
egit-986e3823e1e3555bda426b3b09bd790d4595113a.zip
Fixes obtaining common ancestor in Synchronize view
For obtaining common base ancestor I've used suggested RevWalk with RevFilter.MERGE_BASE. For API compatibility it is also used for obtaining remote variant. This patch also improves the GitResourceVariant implementation. I replaced all dependencies to the deprecated TreeEntry with the proper RevObject implementation. Bug: 317934 CQ: 4390 Change-Id: I8f5352862d01e5a5475a74f222241970cd7960ee Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.egit.core.test')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java379
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest.java213
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest1.java129
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest2.java140
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java223
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitSyncInfoTest.java734
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java20
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java21
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java219
9 files changed, 980 insertions, 1098 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
index 7c9de9015..4fdcca3a9 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantComparatorTest.java
@@ -17,6 +17,7 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.util.Arrays;
import org.eclipse.core.resources.IContainer;
@@ -26,14 +27,15 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
import org.eclipse.egit.core.test.GitTestCase;
-import org.eclipse.jgit.lib.ObjectId;
+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.FileRepository;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.team.core.variants.IResourceVariant;
import org.junit.After;
import org.junit.Before;
@@ -43,27 +45,31 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
private Repository repo;
+ private IProject iProject;
+
+ private TestRepository testRepo;
+
@Before
public void setUp() throws Exception {
super.setUp();
- IProject iProject = project.project;
- if (!gitDir.exists())
- new FileRepository(gitDir).create();
-
- new ConnectProviderOperation(iProject, gitDir).execute(null);
+ iProject = project.project;
+ testRepo = new TestRepository(gitDir);
+ testRepo.connect(iProject);
repo = RepositoryMapping.getMapping(iProject).getRepository();
}
@After
- public void tearDown() throws Exception {
- repo.close();
+ public void clearGitResources() throws Exception {
+ testRepo.disconnect(iProject);
+ testRepo.dispose();
+ repo = null;
super.tearDown();
}
- /*============================================
+ /* ============================================
* compare(IResource, IResourceVariant) tests
- *============================================*/
+ * ============================================ */
/**
* When remote variant wasn't found, compare method is called with null as
@@ -74,7 +80,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
public void shouldReturnFalseWhenRemoteDoesNotExist() {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
IResource local = createMock(IResource.class);
@@ -87,16 +93,16 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
}
/**
- * It is possible to have a local file that has same name as a remote folder.
- * In some cases that two resources can be compared. In this case compare
- * method should return false, because they aren't same resources
+ * It is possible to have a local file that has same name as a remote
+ * folder. In some cases that two resources can be compared. In this case
+ * compare method should return false, because they aren't same resources
*/
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenComparingFileAndContainer() {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
IFile local = createMock(IFile.class);
@@ -113,14 +119,17 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
}
/**
- * Comparing two folders that have different path should return false.
+ * Comparing two folders that have different path should return false.
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenComparingContainerAndContainer() {
+ public void shouldReturnFalseWhenComparingContainerAndContainer()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
IPath localPath = createMock(IPath.class);
@@ -130,53 +139,59 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
expect(local.getFullPath()).andReturn(localPath);
replay(local);
- IPath remotePath = createMock(IPath.class);
- replay(remotePath);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.getFullPath()).andReturn(remotePath);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
+ File file = testRepo.createFile(iProject, "test" + File.separator
+ + "keep");
+ RevCommit commit = testRepo.addAndCommit(iProject, file,
+ "initial commit");
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit, path);
// then
assertFalse(grvc.compare(local, remote));
- verify(local, localPath, remotePath, remoteResource);
+ verify(local, localPath);
}
/**
* When comparing two folders that have same path, compare() method should
* return true.
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnTrueWhenComparingContainerAndContainer() {
+ public void shouldReturnTrueWhenComparingContainerAndContainer()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IPath path = createMock(IPath.class);
- replay(path);
+ File file = testRepo.createFile(iProject, "test" + File.separator
+ + "keep");
+ RevCommit commit = testRepo.addAndCommit(iProject, file,
+ "initial commit");
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+ IPath iPath = new Path(path);
IContainer local = createMock(IContainer.class);
expect(local.exists()).andReturn(true);
- expect(local.getFullPath()).andReturn(path);
+ expect(local.getFullPath()).andReturn(iPath);
replay(local);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.getFullPath()).andReturn(path);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit, path);
// then
assertTrue(grvc.compare(local, remote));
- verify(local, path, remoteResource);
+ verify(local);
}
/**
* Compare() should return false when comparing two files with different
* content length
+ *
* @throws Exception
*/
@Test
@@ -189,7 +204,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -218,6 +233,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
/**
* Comparing two files that have same content length but having small
* difference inside content should return false.
+ *
* @throws Exception
*/
@Test
@@ -230,7 +246,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -259,6 +275,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
/**
* Comparing two 'large' files that have same length and almost identical
* content should return false.
+ *
* @throws Exception
*/
@Test
@@ -273,7 +290,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -306,6 +323,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
* This and previous three test cases cover almost the same functionality
* but they are covering all return points in compare methods that can be
* used when comparing files content
+ *
* @throws Exception
*/
@Test
@@ -320,7 +338,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -349,6 +367,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
/**
* Comparing two files that have the same content and content length should
* return true
+ *
* @throws Exception
*/
@Test
@@ -360,7 +379,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -389,6 +408,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
/**
* Compare two 'large' files that have same content length and content
* should return true.
+ *
* @throws Exception
*/
@Test
@@ -403,7 +423,7 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- dataSet, null);
+ dataSet);
// given
IFile local = createMock(IFile.class);
@@ -429,252 +449,261 @@ public class GitResourceVariantComparatorTest extends GitTestCase {
verify(local, remote, storage);
}
+ /* ==================================================
+ * compare(IResourceVariant, IResourceVariant) tests
+ * ================================================== */
+
/**
- * When comparing locally not existing file with file that exists in remote,
+ * When comparing file that don't exist in base, but exists in remote
* compare method should return false.
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenBaseDoesntExist() {
+ public void shouldReturnFalseWhenBaseDoesntExist() throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(false);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, ObjectId.zeroId(), null);
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
+ RevCommit baseCommit = testRepo.createInitialCommit("initial commit");
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ File file = testRepo.createFile(iProject, "test-file");
+ RevCommit remoteCommit = testRepo.addAndCommit(iProject, file,
+ "second commit");
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
+ baseCommit, path);
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
+ remoteCommit, path);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
/**
* Compare() should return false when remote file does not exists, but
* equivalent local file exist.
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenRemoteVariantDoesntExist() {
+ public void shouldReturnFalseWhenRemoteVariantDoesntExist()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, ObjectId.zeroId(), null);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(false);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
+ RevCommit remoteCommit = testRepo.createInitialCommit("initial commit");
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ File file = testRepo.createFile(iProject, "test-file");
+ RevCommit baseCommit = testRepo.addAndCommit(iProject, file,
+ "second commit");
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
+ baseCommit, path);
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
+ remoteCommit, path);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
- /*==================================================
- * compare(IResourceVariant, IResourceVariant) tests
- *==================================================*/
-
/**
* Return false when comparing incompatible types (file against folder) that
* also maps onto different resources
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenComparingRemoteVariantFileWithContainer() {
+ public void shouldReturnFalseWhenComparingRemoteVariantFileWithContainer()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, ObjectId.zeroId(), null);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
+ File file = testRepo.createFile(iProject, "test" + File.separator
+ + "keep");
+ RevCommit commit = testRepo.addAndCommit(iProject, file,
+ "initial commit");
+ String filePath = Repository.stripWorkDir(repo.getWorkTree(), file);
+ String folderPath = Repository.stripWorkDir(repo.getWorkTree(),
+ new File(file.getParent()));
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
+ commit, filePath);
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit, folderPath);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
/**
* Return false when comparing incompatible types (folder against file) that
* also map onto different resources
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenComparingRemoteVariantContainerWithFile() {
+ public void shouldReturnFalseWhenComparingRemoteVariantContainerWithFile()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
+ File file = testRepo.createFile(iProject, "test" + File.separator
+ + "keep");
+ RevCommit commit = testRepo.addAndCommit(iProject, file,
+ "initial commit");
+ String filePath = Repository.stripWorkDir(repo.getWorkTree(), file);
+ String folderPath = Repository.stripWorkDir(repo.getWorkTree(),
+ new File(file.getParent()));
+
+ GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
+ commit, folderPath);
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
+ commit, filePath);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
/**
* When comparing two remote variants that have different path compare
* method should return false
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnFalseWhenComparingRemoteVariantContainerWithContainer() {
+ public void shouldReturnFalseWhenComparingRemoteVariantContainerWithContainer()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IPath basePath = createMock(IPath.class);
- replay(basePath);
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- expect(baseResource.getFullPath()).andReturn(basePath);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IPath remotePath = createMock(IPath.class);
- replay(remotePath);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- expect(remoteResource.getFullPath()).andReturn(remotePath);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
+ File file1 = testRepo.createFile(iProject, "test1" + File.separator
+ + "keep1");
+ File file2 = testRepo.createFile(iProject, "test2" + File.separator
+ + "keep2");
+ testRepo.track(file1);
+ testRepo.track(file2);
+ testRepo.addToIndex(testRepo.getIFile(iProject, file1));
+ testRepo.addToIndex(testRepo.getIFile(iProject, file2));
+ RevCommit commit = testRepo.commit("initial commit");
+
+ String path1 = Repository.stripWorkDir(repo.getWorkTree(), new File(
+ file1.getParent()));
+ String path2 = Repository.stripWorkDir(repo.getWorkTree(), new File(
+ file2.getParent()));
+
+ GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
+ commit, path1);
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit, path2);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource, basePath, remotePath);
}
/**
* Comparing two remote folders that have same path should return true
+ *
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnTrueWhenComparingRemoteVariantContainerWithContainer() {
+ public void shouldReturnTrueWhenComparingRemoteVariantContainerWithContainer()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IPath path = createMock(IPath.class);
- replay(path);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- expect(baseResource.getFullPath()).andReturn(path);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- expect(remoteResource.getFullPath()).andReturn(path);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
+ File file1 = testRepo.createFile(iProject, "test1" + File.separator
+ + "keep1");
+ testRepo.track(file1);
+ testRepo.addToIndex(testRepo.getIFile(iProject, file1));
+ RevCommit commit = testRepo.commit("initial commit");
+
+ String path1 = Repository.stripWorkDir(repo.getWorkTree(), new File(
+ file1.getParent()));
+
+ GitFolderResourceVariant base = new GitFolderResourceVariant(repo,
+ commit, path1);
+ GitFolderResourceVariant remote = new GitFolderResourceVariant(repo,
+ commit, path1);
// then
assertTrue(grvc.compare(base, remote));
- verify(baseResource, remoteResource, path);
}
@Test
@SuppressWarnings("boxing")
/**
* Comparing two remote files that have different git ObjectId should return false.
+ *
+ * @throws Exception
*/
- public void shouldReturnFalseWhenComparingRemoteVariantWithDifferentObjectId() {
+ public void shouldReturnFalseWhenComparingRemoteVariantWithDifferentObjectId()
+ throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(
- baseResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- null);
+ File file = testRepo.createFile(iProject, "test-file");
+ RevCommit baseCommit = testRepo.appendContentAndCommit(iProject, file,
+ "a", "initial commit");
+ RevCommit remoteCommit = testRepo.appendContentAndCommit(iProject,
+ file, "bc", "second commit");
+
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo,
+ baseCommit, path);
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo,
+ remoteCommit, path);
// then
assertFalse(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
/**
* Comparing two remote files that have the same git ObjectId should return
* true.
+ * @throws Exception
*/
@Test
@SuppressWarnings("boxing")
- public void shouldReturnTrueWhenComparingRemoteVariant() {
+ public void shouldReturnTrueWhenComparingRemoteVariant() throws Exception {
// when
GitResourceVariantComparator grvc = new GitResourceVariantComparator(
- null, null);
+ null);
// given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(
- baseResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- null);
+ File file = testRepo.createFile(iProject, "test-file");
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file,
+ "a", "initial commit");
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- null);
+ String path = Repository.stripWorkDir(repo.getWorkTree(), file);
+ GitBlobResourceVariant base = new GitBlobResourceVariant(repo, commit, path);
+
+ GitBlobResourceVariant remote = new GitBlobResourceVariant(repo, commit, path);
// then
assertTrue(grvc.compare(base, remote));
- verify(baseResource, remoteResource);
}
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest.java
new file mode 100644
index 000000000..32ef36424
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.synchronize;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.core.variants.IResourceVariantTree;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class GitResourceVariantTreeSubscriberTest extends GitTestCase {
+
+ private Repository repo;
+
+ private IProject iProject;
+
+ private TestRepository testRepo;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ iProject = project.getProject();
+ testRepo = new TestRepository(gitDir);
+ testRepo.connect(iProject);
+ repo = RepositoryMapping.getMapping(iProject).getRepository();
+ }
+
+ @After
+ public void clearGitResources() throws Exception {
+ testRepo.disconnect(iProject);
+ testRepo.dispose();
+ repo = null;
+ super.tearDown();
+ }
+
+ /**
+ * This test simulates that user work and made some changes on branch 'test'
+ * and then try to synchronize "test" and 'master' branch.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void shouldReturnSrcBranchAsBase() throws Exception {
+ // when
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file,
+ "class Main {}", "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+ ObjectId fileId = findFileId(commit, mainJava);
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ testRepo.appendContentAndCommit(iProject, file, "// test1",
+ "secont commit");
+
+ // given
+ GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
+ Constants.HEAD, Constants.R_HEADS + Constants.MASTER);
+ grvts.getBaseTree();
+ IResourceVariantTree baseTree = grvts.getBaseTree();
+
+ // then
+ IResourceVariant actual = commonAssertionsForBaseTree(baseTree,
+ mainJava);
+ assertEquals(fileId.getName(), actual.getContentIdentifier());
+ }
+
+ /**
+ * Both source and destination branches has some different commits but they
+ * has also common ancestor. This situation is described more detailed in
+ * bug #317934
+ *
+ * This test passes when it is run as a stand alone test case, but it fails
+ * when it is run as part of test suite. It throws NPE when it try's to
+ * checkout master branch.
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void shouldReturnCommonAncestorAsBase() throws Exception {
+ // when
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file,
+ "class Main {}", "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+ // this should be our common ancestor
+ ObjectId fileId = findFileId(commit, mainJava);
+
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ testRepo.appendContentAndCommit(iProject, file, "// test 1",
+ "second commit");
+
+ testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER);
+ testRepo.appendContentAndCommit(iProject, file, "// test 2",
+ "third commit");
+
+ // given
+ GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
+ Constants.HEAD, Constants.R_HEADS + "test");
+ grvts.getBaseTree();
+ IResourceVariantTree baseTree = grvts.getBaseTree();
+
+ // then
+ IResourceVariant actual = commonAssertionsForBaseTree(baseTree,
+ mainJava);
+ assertEquals(fileId.getName(), actual.getContentIdentifier());
+ }
+
+ /**
+ * This test passes when it is run as a stand alone test case, but it fails
+ * when it is run as part of test suite. It throws NPE when it try's to
+ * checkout master branch.
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore
+ public void shouldReturnRemoteTree() throws Exception {
+ // when
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ testRepo.appendContentAndCommit(iProject, file,
+ "class Main {}", "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "// test 1",
+ "second commit");
+ ObjectId fileId = findFileId(commit, mainJava);
+
+ // given
+ GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
+ Constants.HEAD, "test");
+ grvts.getBaseTree();
+ IResourceVariantTree remoteTree = grvts.getRemoteTree();
+
+ // then
+ assertNotNull(remoteTree);
+ assertTrue(remoteTree instanceof GitRemoteResourceVariantTree);
+ IResourceVariant resourceVariant = remoteTree
+ .getResourceVariant(mainJava);
+ assertNotNull(resourceVariant);
+ assertTrue(resourceVariant instanceof GitResourceVariant);
+ assertEquals(fileId.getName(), resourceVariant.getContentIdentifier());
+ }
+
+ private GitResourceVariantTreeSubscriber createGitResourceVariantTreeSubscriber(
+ String src, String dst) {
+ GitSynchronizeData gsd = new GitSynchronizeData(repo, src, dst, false);
+ GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
+ new GitResourceVariantTreeSubscriber(gsds);
+ return new GitResourceVariantTreeSubscriber(gsds);
+ }
+
+ private ObjectId findFileId(RevCommit commit, IFile mainJava)
+ throws Exception {
+ TreeWalk tw = new TreeWalk(repo);
+ tw.reset();
+ tw.setRecursive(true);
+ String path = Repository.stripWorkDir(repo.getWorkTree(), mainJava
+ .getLocation().toFile());
+ tw.setFilter(PathFilter.create(path));
+ int nth = tw.addTree(commit.getTree());
+ tw.next();
+
+ return tw.getObjectId(nth);
+ }
+
+ private IResourceVariant commonAssertionsForBaseTree(
+ IResourceVariantTree baseTree, IResource resource)
+ throws TeamException {
+ assertNotNull(baseTree);
+ assertTrue(baseTree instanceof GitBaseResourceVariantTree);
+ IResourceVariant resourceVariant = baseTree
+ .getResourceVariant(resource);
+ assertNotNull(resourceVariant);
+ assertTrue(resourceVariant instanceof GitResourceVariant);
+ return resourceVariant;
+ }
+
+}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest1.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest1.java
new file mode 100644
index 000000000..dd4cb7db1
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest1.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.synchronize;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.core.variants.IResourceVariantTree;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GitResourceVariantTreeSubscriberTest1 extends GitTestCase {
+
+ private Repository repo;
+
+ private IProject iProject;
+
+ private TestRepository testRepo;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ iProject = project.getProject();
+ testRepo = new TestRepository(gitDir);
+ testRepo.connect(iProject);
+ repo = RepositoryMapping.getMapping(iProject).getRepository();
+ }
+
+ @After
+ public void clearGitResources() throws Exception {
+ testRepo.disconnect(iProject);
+ testRepo.dispose();
+ repo = null;
+ super.tearDown();
+ }
+
+ /**
+ * This test simulates that user work and made some changes on branch 'test'
+ * and then try to synchronize "test" and 'master' branch.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void shouldReturnSrcBranchAsBase() throws Exception {
+ // when
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file,
+ "class Main {}", "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+ ObjectId fileId = findFileId(commit, mainJava);
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ testRepo.appendContentAndCommit(iProject, file, "// test1",
+ "secont commit");
+
+ // given
+ GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
+ Constants.HEAD, Constants.R_HEADS + Constants.MASTER);
+ grvts.getBaseTree();
+ IResourceVariantTree baseTree = grvts.getBaseTree();
+
+ // then
+ IResourceVariant actual = commonAssertionsForBaseTree(baseTree,
+ mainJava);
+ assertEquals(fileId.getName(), actual.getContentIdentifier());
+ }
+
+ private GitResourceVariantTreeSubscriber createGitResourceVariantTreeSubscriber(
+ String src, String dst) {
+ GitSynchronizeData gsd = new GitSynchronizeData(repo, src, dst, false);
+ GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
+ new GitResourceVariantTreeSubscriber(gsds);
+ return new GitResourceVariantTreeSubscriber(gsds);
+ }
+
+ private ObjectId findFileId(RevCommit commit, IFile mainJava)
+ throws Exception {
+ TreeWalk tw = new TreeWalk(repo);
+ tw.reset();
+ tw.setRecursive(true);
+ String path = Repository.stripWorkDir(repo.getWorkTree(), mainJava
+ .getLocation().toFile());
+ tw.setFilter(PathFilter.create(path));
+ int nth = tw.addTree(commit.getTree());
+ tw.next();
+
+ return tw.getObjectId(nth);
+ }
+
+ private IResourceVariant commonAssertionsForBaseTree(
+ IResourceVariantTree baseTree, IResource resource)
+ throws TeamException {
+ assertNotNull(baseTree);
+ assertTrue(baseTree instanceof GitBaseResourceVariantTree);
+ IResourceVariant resourceVariant = baseTree
+ .getResourceVariant(resource);
+ assertNotNull(resourceVariant);
+ assertTrue(resourceVariant instanceof GitResourceVariant);
+ return resourceVariant;
+ }
+
+}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest2.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest2.java
new file mode 100644
index 000000000..4a12d331b
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest2.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.synchronize;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.core.variants.IResourceVariantTree;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GitResourceVariantTreeSubscriberTest2 extends GitTestCase {
+
+ private Repository repo;
+
+ private IProject iProject;
+
+ private TestRepository testRepo;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ iProject = project.getProject();
+ testRepo = new TestRepository(gitDir);
+ testRepo.connect(iProject);
+ repo = RepositoryMapping.getMapping(iProject).getRepository();
+ }
+
+ @After
+ public void clearGitResources() throws Exception {
+ testRepo.disconnect(iProject);
+ testRepo.dispose();
+ repo = null;
+ super.tearDown();
+ }
+
+ /**
+ * Both source and destination branches has some different commits but they
+ * has also common ancestor. This situation is described more detailed in
+ * bug #317934
+ *
+ * This test passes when it is run as a stand alone test case, but it fails
+ * when it is run as part of test suite. It throws NPE when it try's to
+ * checkout master branch.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void shouldReturnCommonAncestorAsBase() throws Exception {
+ // when
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ RevCommit commit = testRepo.appendContentAndCommit(iProject, file,
+ "class Main {}", "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+ // this should be our common ancestor
+ ObjectId fileId = findFileId(commit, mainJava);
+
+ testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
+ + "test");
+ testRepo.appendContentAndCommit(iProject, file, "// test 1",
+ "second commit");
+
+ testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER);
+ testRepo.appendContentAndCommit(iProject, file, "// test 2",
+ "third commit");
+
+ // given
+ GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
+ Constants.HEAD, Constants.R_HEADS + "test");
+ grvts.getBaseTree();
+ IResourceVariantTree baseTree = grvts.getBaseTree();
+
+ // then
+ IResourceVariant actual = commonAssertionsForBaseTree(baseTree,
+ mainJava);
+ assertEquals(fileId.getName(), actual.getContentIdentifier());
+ }
+
+ private GitResourceVariantTreeSubscriber createGitResourceVariantTreeSubscriber(
+ String src, String dst) {
+ GitSynchronizeData gsd = new GitSynchronizeData(repo, src, dst, false);
+ GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
+ new GitResourceVariantTreeSubscriber(gsds);
+ return new GitResourceVariantTreeSubscriber(gsds);
+ }
+
+ private ObjectId findFileId(RevCommit commit, IFile mainJava)
+ throws Exception {
+ TreeWalk tw = new TreeWalk(repo);
+ tw.reset();
+ tw.setRecursive(true);
+ String path = Repository.stripWorkDir(repo.getWorkTree(), mainJava
+ .getLocation().toFile());
+ tw.setFilter(PathFilter.create(path));
+ int nth = tw.addTree(commit.getTree());
+ tw.next();
+
+ return tw.getObjectId(nth);
+ }
+
+ private IResourceVariant commonAssertionsForBaseTree(
+ IResourceVariantTree baseTree, IResource resource)
+ throws TeamException {
+ assertNotNull(baseTree);
+ assertTrue(baseTree instanceof GitBaseResourceVariantTree);
+ IResourceVariant resourceVariant = baseTree
+ .getResourceVariant(resource);
+ assertNotNull(resourceVariant);
+ assertTrue(resourceVariant instanceof GitResourceVariant);
+ return resourceVariant;
+ }
+
+}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
index 7d23d5f94..f18972b66 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeTest.java
@@ -15,67 +15,54 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.egit.core.op.AddToIndexOperation;
-import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
-import org.eclipse.egit.core.op.DisconnectProviderOperation;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
import org.eclipse.egit.core.test.GitTestCase;
import org.eclipse.egit.core.test.TestProject;
+import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.core.variants.ResourceVariantByteStore;
-import org.eclipse.team.core.variants.SessionResourceVariantByteStore;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class GitResourceVariantTreeTest extends GitTestCase {
private Repository repo;
+ private IProject iProject;
+
+ private TestRepository testRepo;
+
private ResourceVariantByteStore store;
@Before
public void createGitRepository() throws Exception {
- IProject iProject = project.project;
- if (!gitDir.exists())
- new FileRepository(gitDir).create();
-
- new ConnectProviderOperation(iProject, gitDir).execute(null);
+ iProject = project.project;
+ testRepo = new TestRepository(gitDir);
+ testRepo.connect(iProject);
repo = RepositoryMapping.getMapping(iProject).getRepository();
-
- store = new SessionResourceVariantByteStore();
}
@After
public void clearGitResources() throws Exception {
- List<IProject> projects = new ArrayList<IProject>();
- projects.add(project.project);
- new DisconnectProviderOperation(projects).execute(null);
-
- repo.close();
+ testRepo.disconnect(iProject);
+ testRepo.dispose();
+ repo = null;
super.tearDown();
}
@@ -104,6 +91,7 @@ public class GitResourceVariantTreeTest extends GitTestCase {
* When we have two or more project associated with repository, roots()
* method should return list of project. In this case we have two project
* associated with particular repository, therefore '2' value is expected.
+ *
* @throws Exception
*/
@Test
@@ -130,72 +118,10 @@ public class GitResourceVariantTreeTest extends GitTestCase {
}
/**
- * When we want to obtain list of members, members() method should return
- * only members that are in repository. In this test we create Main.java
- * file, stage it and commit it. Then we create Main2.java file with we don't
- * add to repository. members() method should return one member because only
- * one file is in repository.
- * @throws Exception
- */
- @Test
- public void shouldReturnOneMember() throws Exception {
- // when
- createResourceAndCommit("org.egit.test", "Main.java", "class Main {}",
- "Initial commit");
- // create second file that isn't tracked
- IPackageFragment iPackage = project
- .createPackage("org.egit.test.nested");
- project.createType(iPackage, "Main2.java", "class Main2 {}");
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
- GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
-
- // given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
-
- // then
- assertEquals(1, grvt.members(project.project).length);
- IResource[] members = grvt.members(project.project);
- assertEquals("src", members[0].getName());
- }
-
- /**
- * members() method should return only members that are on same level (it
- * cannot work recursively). In this test it should return one file and one
- * folder member.
- * @throws Exception
- */
- @Ignore
- @Test
- public void shouldReturnTwoMembers() throws Exception {
- // when
- IPackageFragment iPackage = project.createPackage("org.egit.test");
- createResourceAndCommit(iPackage, "Main.java", "class Main {}",
- "Initial commit");
- // create second file that isn't tracked
- createResourceAndCommit("org.egit.test.nested", "Main2.java",
- "class Main2 {}", "Second commit");
-
- GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
- Constants.MASTER, false);
- GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
-
- // given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
-
- // then
- assertEquals(2, grvt.members(iPackage.getResource()).length);
- IResource[] members = grvt.members(iPackage.getResource());
- assertEquals("nested", members[0].getName());
- assertEquals("Main.java", members[1].getName());
- }
-
- /**
* Checks that getResourceVariant will not throw NPE for null argument. This
* method is called with null argument when local or remote resource does
* not exist.
+ *
* @throws Exception
*/
@Test
@@ -206,8 +132,7 @@ public class GitResourceVariantTreeTest extends GitTestCase {
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
+ GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet);
// then
assertNull(grvt.getResourceVariant(null));
@@ -216,6 +141,7 @@ public class GitResourceVariantTreeTest extends GitTestCase {
/**
* getResourceVariant() should return null when given resource doesn't exist
* in repository.
+ *
* @throws Exception
*/
@Test
@@ -229,8 +155,7 @@ public class GitResourceVariantTreeTest extends GitTestCase {
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
+ GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet);
// then
assertNull(grvt.getResourceVariant(mainJava.getResource()));
@@ -240,35 +165,34 @@ public class GitResourceVariantTreeTest extends GitTestCase {
* Check if getResourceVariant() does return the same resource that was
* committed. Passes only when it is run as a single test, not as a part of
* largest test suite
+ *
* @throws Exception
*/
- @Ignore
@Test
public void shoulReturnSameResourceVariant() throws Exception {
// when
- IType mainJava = createResourceAndCommit("org.egit.test", "Main.java",
- "class Main {}", "Initial commit");
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ testRepo.appendContentAndCommit(iProject, file, "class Main {}",
+ "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
Constants.MASTER, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
+ GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet);
// then
- IResourceVariant actual = grvt.getResourceVariant(mainJava
- .getResource());
+ IResourceVariant actual = grvt.getResourceVariant(mainJava);
assertNotNull(actual);
- assertEquals("Main.java", actual.getName());
+ assertEquals(fileName, actual.getName());
InputStream actualIn = actual.getStorage(new NullProgressMonitor())
.getContents();
- byte[] actualByte = new byte[actualIn.available()];
- actualIn.read(actualByte);
- InputStream expectedIn = ((IFile) mainJava.getResource()).getContents();
- byte[] expectedByte = new byte[expectedIn.available()];
- expectedIn.read(expectedByte);
+ byte[] actualByte = getBytesAndCloseStream(actualIn);
+ InputStream expectedIn = mainJava.getContents();
+ byte[] expectedByte = getBytesAndCloseStream(expectedIn);
assertArrayEquals(expectedByte, actualByte);
}
@@ -278,89 +202,52 @@ public class GitResourceVariantTreeTest extends GitTestCase {
* getResourceVariant() should obtain Main.java file content from "master"
* branch. Passes only when it is run as a single test, not as a part of
* largest test suite
+ *
* @throws Exception
*/
- @Ignore
@Test
public void shouldReturnDifferentResourceVariant() throws Exception {
// when
- IType mainJava = createResourceAndCommit("org.egit.test", "Main.java",
- "class Main {}", "Initial commit");
- createBranch("test");
- // checkout branch
- new BranchOperation(repo, "refs/heads/test").execute(null);
- ((IFile) mainJava.getResource()).appendContents(
- new ByteArrayInputStream("// test".getBytes()), 0, null);
- addAndCommitResource(mainJava, "Second commit");
+ String fileName = "Main.java";
+ File file = testRepo.createFile(iProject, fileName);
+ testRepo.appendContentAndCommit(iProject, file, "class Main {}",
+ "initial commit");
+ IFile mainJava = testRepo.getIFile(iProject, file);
+
+ testRepo.createAndCheckoutBranch(Constants.R_HEADS + Constants.MASTER, Constants.R_HEADS + "test");
+ testRepo.appendContentAndCommit(iProject, file, "// test", "first commit");
GitSynchronizeData data = new GitSynchronizeData(repo, Constants.HEAD,
Constants.MASTER, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
- GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet,
- store);
+ GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet);
// then
- IResourceVariant actual = grvt.getResourceVariant(mainJava
- .getResource());
+ IResourceVariant actual = grvt.getResourceVariant(mainJava);
assertNotNull(actual);
- assertEquals("Main.java", actual.getName());
+ assertEquals(fileName, actual.getName());
InputStream actualIn = actual.getStorage(new NullProgressMonitor())
- .getContents();
- byte[] actualByte = new byte[actualIn.available()];
- actualIn.read(actualByte);
- InputStream expectedIn = ((IFile) mainJava.getResource()).getContents();
- byte[] expectedByte = new byte[expectedIn.available()];
- expectedIn.read(expectedByte);
+ .getContents();
+ byte[] actualByte = getBytesAndCloseStream(actualIn);
+ InputStream expectedIn = mainJava.getContents();
+ byte[] expectedByte = getBytesAndCloseStream(expectedIn);
// assert arrays not equals
- if (Arrays.equals(expectedByte, actualByte)) {
+ if (Arrays.equals(expectedByte, actualByte))
fail();
- } else {
+ else
assertTrue(true);
- }
}
- private IType createResourceAndCommit(String packageName, String fileName,
- String fileContent, String commitMsg) throws Exception {
- IPackageFragment iPackage = project.createPackage(packageName);
- return createResourceAndCommit(iPackage, fileName, fileContent,
- commitMsg);
- }
-
- private IType createResourceAndCommit(IPackageFragment iPackage,
- String fileName, String fileContent, String commitMsg)
- throws Exception {
- IType mainJava = project.createType(iPackage, fileName, fileContent);
- addAndCommitResource(mainJava, commitMsg);
-
- return mainJava;
- }
-
- private void addAndCommitResource(IType mainJava, String commitMsg)
- throws Exception {
- List<IResource> resources = new ArrayList<IResource>();
- resources.add(mainJava.getResource());
- new AddToIndexOperation(resources).execute(null); // add resource to git
- new Git(repo).commit().setMessage(commitMsg).call(); // make commit
- }
-
- private void createBranch(String branchName) throws Exception {
- RefUpdate updateRef;
- updateRef = repo.updateRef(Constants.R_HEADS + branchName);
- Ref startRef = repo.getRef(branchName);
- ObjectId startAt = repo.resolve(Constants.HEAD);
- String startBranch;
- if (startRef != null)
- startBranch = branchName;
- else
- startBranch = startAt.name();
- startBranch = repo.shortenRefName(startBranch);
- updateRef.setNewObjectId(startAt);
- updateRef
- .setRefLogMessage("branch: Created from " + startBranch, false); //$NON-NLS-1$
- updateRef.update();
+ private byte[] getBytesAndCloseStream(InputStream stream) throws Exception {
+ try {
+ byte[] actualByte = new byte[stream.available()];
+ stream.read(actualByte);
+ return actualByte;
+ } finally {
+ stream.close();
+ }
}
-
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitSyncInfoTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitSyncInfoTest.java
deleted file mode 100644
index 22f858857..000000000
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitSyncInfoTest.java
+++ /dev/null
@@ -1,734 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.egit.core.synchronize;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.eclipse.team.core.synchronize.SyncInfo.ADDITION;
-import static org.eclipse.team.core.synchronize.SyncInfo.CHANGE;
-import static org.eclipse.team.core.synchronize.SyncInfo.CONFLICTING;
-import static org.eclipse.team.core.synchronize.SyncInfo.DELETION;
-import static org.eclipse.team.core.synchronize.SyncInfo.INCOMING;
-import static org.eclipse.team.core.synchronize.SyncInfo.IN_SYNC;
-import static org.eclipse.team.core.synchronize.SyncInfo.OUTGOING;
-import static org.eclipse.team.core.synchronize.SyncInfo.PSEUDO_CONFLICT;
-import static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.util.Arrays;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.egit.core.op.ConnectProviderOperation;
-import org.eclipse.egit.core.project.RepositoryMapping;
-import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
-import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
-import org.eclipse.egit.core.test.GitTestCase;
-import org.eclipse.jgit.api.CommitCommand;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.lib.GitIndex;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.GitIndex.Entry;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevCommitList;
-import org.eclipse.jgit.storage.file.FileRepository;
-import org.junit.Before;
-import org.junit.Test;
-
-public class GitSyncInfoTest extends GitTestCase {
-
- private Repository repo;
-
- private GitResourceVariantComparator comparator;
-
- @Before
- public void setUp() throws Exception {
- super.setUp();
- IProject iProject = project.project;
- if (!gitDir.exists())
- new FileRepository(gitDir).create();
-
- new ConnectProviderOperation(iProject, gitDir).execute(null);
- repo = RepositoryMapping.getMapping(iProject).getRepository();
-
- GitSynchronizeData data = new GitSynchronizeData(repo, "", "", true);
- GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
- comparator = new GitResourceVariantComparator(dataSet, null);
- }
-
- /**
- * File is in sync when local, base and remote objects refer to identical
- * file (same git ObjectId).
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnResourceFileInSync() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- ObjectId objectId = stageAndCommit(fileName, localBytes);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, null);
-
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, objectId, null);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(IN_SYNC, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Folders are in sync when they have same name.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnResourceFolderInSync() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(3);
- expect(local.getName()).andReturn("src").anyTimes();
- replay(local);
-
- GitFolderResourceVariant base = new GitFolderResourceVariant(local);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(local);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(IN_SYNC, gsi.getKind());
- verify(local);
- }
-
- /**
- * Outgoing change should be returned when base RevCommitList has more
- * commits than remote RevCommitList
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnOutgoingFileChange() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- stage(fileName, localBytes);
- RevCommit firstCommit = commit();
- localBytes[8120] = 'b';
- ObjectId objectId = stage(fileName, localBytes);
- RevCommit secondCommit = commit();
- RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
- baseCommits.add(firstCommit);
- baseCommits.add(secondCommit);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, baseCommits); // baseComits has two entry
-
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
- RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
- remoteCommits.add(firstCommit);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- remoteCommits); // remoteCommits has only one entry
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(OUTGOING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Should return incoming change when remote RevCommitList has more commit
- * objects then base RevCommitList
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnIncomingFileChange() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- ObjectId objectId = stage(fileName, localBytes);
- RevCommit firstCommit = commit();
- RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
- baseCommits.add(firstCommit);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, baseCommits); // baseCommits has one element
-
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
-
- stage(fileName, localBytes);
- RevCommit secondCommit = commit();
- RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
- remoteCommits.add(secondCommit);
- remoteCommits.add(firstCommit);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- remoteCommits); // remoteCommits has two elements
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(INCOMING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Outgoing deletion should be returned when resource exist in base and
- * remote but does not exist locally.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnOutgoingDeletion() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IPath path = createMock(IPath.class);
- replay(path);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- expect(baseResource.getFullPath()).andReturn(path);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- expect(remoteResource.getFullPath()).andReturn(path);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(OUTGOING | DELETION, gsi.getKind());
- verify(local, baseResource, remoteResource, path);
- }
-
- /**
- * Incoming deletion should be returned when file exists locally and in base
- * but does not exist in remote resource variant.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnIncomingFileDeletion() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- stage(fileName, localBytes);
- RevCommit firstCommit = commit();
- ObjectId objectId = stage(fileName, localBytes);
- RevCommit secondCommit = commit();
- RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
- baseCommits.add(firstCommit);
- baseCommits.add(secondCommit);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, baseCommits);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, null, comparator);
- gsi.init();
-
- // then
- assertEquals(INCOMING | DELETION, gsi.getKind());
- verify(local, baseResource);
- }
-
- /**
- * Outgoing addition should be returned when resource exists locally but it
- * can't be found in base and remote resource variant.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnOutgoingAddition() throws Exception {
- // when
-
- // given
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true).times(2);
- expect(baseResource.isDerived()).andReturn(false);
- expect(baseResource.getName()).andReturn("Mian.java").anyTimes();
- replay(baseResource);
- GitSyncInfo gsi = new GitSyncInfo(baseResource, null, null, comparator);
- gsi.init();
-
- // then
- assertEquals(OUTGOING | ADDITION, gsi.getKind());
- verify(baseResource);
- }
-
- /**
- * Conflicting change should be returned when remote and base RevCommitList
- * have same number of RevCommit object's but these lists have one ore more
- * different RevCommit objects.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFileChange() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- ObjectId objectId = stage(fileName, localBytes);
- RevCommit firstCommit = commit();
- RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
- baseCommits.add(firstCommit);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, baseCommits);
-
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
-
- stage(fileName, localBytes);
- RevCommit secondCommit = commit();
- RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
- remoteCommits.add(secondCommit);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource,
- repo,
- ObjectId.fromString("0123456789012345678901234567890123456789"),
- remoteCommits);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Conflicting change should be returned when file was created locally with
- * same name as incoming folder in remote.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFileChange1() throws Exception {
- // when
-
- // given
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(1);
- expect(local.getName()).andReturn("test-file").anyTimes();
- replay(local);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, null, null);
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Conflicting change should be returned when local resource differ from
- * base resource variant and remote variant does not exist.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFileChange2() throws Exception {
- // when
-
- // given
- String fileName = "test-file";
- byte[] localBytes = new byte[8200];
- Arrays.fill(localBytes, (byte) 'a');
-
- IFile local = createMock(IFile.class);
- expect(local.isDerived()).andReturn(false);
- expect(local.exists()).andReturn(true).times(2);
- expect(local.getName()).andReturn(fileName).anyTimes();
- expect(local.getProject()).andReturn(project.getProject());
- expect(local.getContents()).andReturn(
- new ByteArrayInputStream(localBytes));
- replay(local);
-
- stage(fileName, localBytes);
- RevCommit firstCommit = commit();
- byte[] remoteBytes = new byte[localBytes.length];
- System.arraycopy(localBytes, 0, remoteBytes, 0, localBytes.length);
- remoteBytes[8100] = 'b';
- ObjectId objectId = stage(fileName, remoteBytes);
- RevCommit secondCommit = commit();
- RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
- baseCommits.add(firstCommit);
- baseCommits.add(secondCommit);
-
- IFile baseResource = createMock(IFile.class);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, objectId, baseCommits);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, null, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource);
- }
-
- /**
- * Conflicting change when folder exists locally and remotely but it does
- * not exist in base resource variant.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFolderChange() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(true);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(false);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Conflicting change when folder exists in base but it does not exist in
- * local and remote.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFolderChange1() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(false);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(false);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /*
- * When local resource is file, base resource variant is folder and remote
- * variant is a file, then getKind() should return conflicting change.
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFolderAndFileChange() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(false);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * When remote is folder and base is a file getKind() should return
- * conflicting change
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingFileAndFolderChange() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(false);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource baseResource = createMock(IResource.class);
- expect(baseResource.exists()).andReturn(true);
- replay(baseResource);
- GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource,
- repo, ObjectId.zeroId(), null);
-
- IResource remoteResource = createMock(IResource.class);
- expect(remoteResource.exists()).andReturn(true);
- replay(remoteResource);
- GitFolderResourceVariant remote = new GitFolderResourceVariant(
- remoteResource);
- GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | CHANGE, gsi.getKind());
- verify(local, baseResource, remoteResource);
- }
-
- /**
- * Remote resource variant was not found, local resource does not exist but
- * there is a base resource. In such situation we should return conflicting
- * deletion.
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingDeletationPseudoConflict()
- throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(false);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource baseResource = createMock(IResource.class);
- replay(baseResource);
- GitFolderResourceVariant base = new GitFolderResourceVariant(
- baseResource);
-
- GitSyncInfo gsi = new GitSyncInfo(local, base, null, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | DELETION | PSEUDO_CONFLICT, gsi.getKind());
- verify(local, baseResource);
- }
-
- /**
- * Conflicting addition should be returned when resource exists in local and
- * remote but cannot be found in base
- * @throws Exception
- */
- @Test
- @SuppressWarnings("boxing")
- public void shouldReturnConflictingAddition() throws Exception {
- // when
-
- // given
- IResource local = createMock(IResource.class);
- expect(local.exists()).andReturn(true).times(3);
- expect(local.isDerived()).andReturn(false);
- expect(local.getName()).andReturn("Mian.java").anyTimes();
- replay(local);
-
- IResource remoteResource = createMock(IResource.class);
- replay(remoteResource);
- GitBlobResourceVariant remote = new GitBlobResourceVariant(
- remoteResource, repo, ObjectId.zeroId(), null);
- GitSyncInfo gsi = new GitSyncInfo(local, null, remote, comparator);
- gsi.init();
-
- // then
- assertEquals(CONFLICTING | ADDITION, gsi.getKind());
- verify(local, remoteResource);
- }
-
- private ObjectId stageAndCommit(String fileName, byte[] content)
- throws Exception {
- ObjectId objectId = stage(fileName, content);
- commit();
-
- return objectId;
- }
-
- private ObjectId stage(String fileName, byte[] content) throws Exception {
- // TODO reimplement using DirCache class
- GitIndex index = repo.getIndex();
- File workdir = project.getProject().getFullPath().toFile();
- File file = new File(workdir, fileName);
- Entry entry = index.add(workdir, file, content);
- index.write();
-
- return entry.getObjectId();
- }
-
- private RevCommit commit() throws Exception {
- Git git = new Git(repo);
- CommitCommand commit = git.commit();
- commit.setMessage("Initial commit");
- commit.setAuthor("EGit", "egi@eclipse.org");
- return commit.call();
- }
-
-}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java
index 0cdd595f7..fbbd67bd8 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitTestResourceVariantTree.java
@@ -8,12 +8,10 @@
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
-import java.io.IOException;
-
-import org.eclipse.core.resources.IResource;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.Tree;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.ResourceVariantByteStore;
/**
@@ -25,18 +23,12 @@ class GitTestResourceVariantTree extends GitResourceVariantTree {
GitTestResourceVariantTree(GitSynchronizeDataSet data,
ResourceVariantByteStore store) {
- super(data, store);
- }
-
- @Override
- ObjectId getRevObjId(IResource resource) throws IOException {
- // not used in test case
- return null;
+ super(store, data);
}
@Override
- Tree getRevTree(IResource resource) throws IOException {
- // TODO not used in test case
+ protected RevCommit getRevCommit(GitSynchronizeData gsd)
+ throws TeamException {
return null;
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
index 2ec001411..0cd8f283b 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestProject.java
@@ -9,10 +9,13 @@
*******************************************************************************/
package org.eclipse.egit.core.test;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
@@ -111,6 +114,24 @@ public class TestProject {
return cu.getTypes()[0];
}
+ public IFile createFile(String name, byte[] content) throws Exception {
+ IFile file = project.getFile(name);
+ InputStream inputStream = new ByteArrayInputStream(content);
+ file.create(inputStream, true, null);
+
+ return file;
+ }
+
+ public IFolder createFolder(String name) throws Exception {
+ IFolder folder = project.getFolder(name);
+ folder.create(true, true, null);
+
+ IFile keep = project.getFile(name + "/keep");
+ keep.create(new ByteArrayInputStream(new byte[] {0}), true, null);
+
+ return folder;
+ }
+
public void dispose() throws CoreException, IOException {
waitForIndexer();
if (project.exists())
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
index cd5a5a87f..fb68ba22a 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/TestRepository.java
@@ -11,12 +11,18 @@ package org.eclipse.egit.core.test;
import static org.junit.Assert.assertNotNull;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
+import org.eclipse.egit.core.op.DisconnectProviderOperation;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.Git;
@@ -28,12 +34,12 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.GitIndex;
+import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tree;
-import org.eclipse.jgit.lib.GitIndex.Entry;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepository;
@@ -44,6 +50,7 @@ import org.eclipse.jgit.storage.file.FileRepository;
public class TestRepository {
Repository repository;
+
String workdirPrefix;
/**
@@ -61,12 +68,13 @@ public class TestRepository {
workdirPrefix = repository.getWorkTree().getAbsolutePath();
}
workdirPrefix = workdirPrefix.replace('\\', '/');
- if (!workdirPrefix.endsWith("/")) //$NON-NLS-1$
- workdirPrefix += "/"; //$NON-NLS-1$
+ if (!workdirPrefix.endsWith("/")) //$NON-NLS-1$
+ workdirPrefix += "/"; //$NON-NLS-1$
}
/**
* Creates a test repository from an existing Repository
+ *
* @param repository
* @throws IOException
*/
@@ -78,8 +86,8 @@ public class TestRepository {
workdirPrefix = repository.getWorkTree().getAbsolutePath();
}
workdirPrefix = workdirPrefix.replace('\\', '/');
- if (!workdirPrefix.endsWith("/")) //$NON-NLS-1$
- workdirPrefix += "/"; //$NON-NLS-1$
+ if (!workdirPrefix.endsWith("/")) //$NON-NLS-1$
+ workdirPrefix += "/"; //$NON-NLS-1$
}
/**
@@ -113,6 +121,81 @@ public class TestRepository {
}
/**
+ * Create new file
+ *
+ * @param project
+ * instance of project inside with file will be created
+ * @param name
+ * name of file
+ * @return nearly created file
+ * @throws IOException
+ */
+ public File createFile(IProject project, String name) throws IOException {
+ String path = project.getLocation().append(name).toOSString();
+ int lastSeparator = path.lastIndexOf(File.separator);
+ new File(path.substring(0, lastSeparator)).mkdirs();
+
+ File file = new File(path);
+ file.createNewFile();
+
+ return file;
+ }
+
+ /**
+ * Track, add to index and finally commit given file
+ *
+ * @param project
+ * @param file
+ * @param commitMessage
+ * @return commit object
+ * @throws Exception
+ */
+ public RevCommit addAndCommit(IProject project, File file, String commitMessage)
+ throws Exception {
+ track(file);
+ addToIndex(project, file);
+
+ return commit(commitMessage);
+ }
+
+ /**
+ * Appends file content to given file, then track, add to index and finally
+ * commit it.
+ *
+ * @param project
+ * @param file
+ * @param content
+ * @param commitMessage
+ * @return commit object
+ * @throws Exception
+ */
+ public RevCommit appendContentAndCommit(IProject project, File file,
+ byte[] content, String commitMessage) throws Exception {
+ return appendContentAndCommit(project, file, new String(content),
+ commitMessage);
+ }
+
+ /**
+ * Appends file content to given file, then track, add to index and finally
+ * commit it.
+ *
+ * @param project
+ * @param file
+ * @param content
+ * @param commitMessage
+ * @return commit object
+ * @throws Exception
+ */
+ public RevCommit appendContentAndCommit(IProject project, File file,
+ String content, String commitMessage) throws Exception {
+ appendFileContent(file, content);
+ track(file);
+ addToIndex(project, file);
+
+ return commit(commitMessage);
+ }
+
+ /**
* Commits the current index
*
* @param message
@@ -152,6 +235,19 @@ public class TestRepository {
}
/**
+ * Creates a new branch and immediately checkout it.
+ *
+ * @param refName
+ * starting point for the new branch
+ * @param newRefName
+ * @throws Exception
+ */
+ public void createAndCheckoutBranch(String refName, String newRefName) throws Exception {
+ createBranch(refName, newRefName);
+ checkoutBranch(newRefName);
+ }
+
+ /**
* Creates a new branch
*
* @param refName
@@ -178,13 +274,39 @@ public class TestRepository {
}
/**
+ * Checkouts branch
+ *
+ * @param refName
+ * full name of branch
+ * @throws CoreException
+ */
+ public void checkoutBranch(String refName) throws CoreException {
+ new BranchOperation(repository, refName).execute(null);
+ }
+
+ /**
+ * Adds the given file to the index
+ *
+ * @param project
+ * @param file
+ * @throws Exception
+ */
+ public void addToIndex(IProject project, File file) throws Exception {
+ IFile iFile = getIFile(project, file);
+ addToIndex(iFile);
+ }
+
+
+ /**
* Adds the given file to the index
+ *
* @param file
* @throws IOException
*/
public void addToIndex(IFile file) throws IOException {
GitIndex index = repository.getIndex();
- Entry entry = index.getEntry(getRepoRelativePath(file.getLocation().toOSString()));
+ Entry entry = index.getEntry(getRepoRelativePath(file.getLocation()
+ .toOSString()));
assertNotNull(entry);
if (entry.isModified(repository.getWorkTree()))
entry.update(new File(repository.getWorkTree(), entry.getName()));
@@ -192,7 +314,62 @@ public class TestRepository {
}
/**
+ * Appends content to end of given file.
+ *
+ * @param file
+ * @param content
+ * @throws IOException
+ */
+ public void appendFileContent(File file, byte[] content) throws IOException {
+ appendFileContent(file, new String(content), true);
+ }
+
+ /**
+ * Appends content to end of given file.
+ *
+ * @param file
+ * @param content
+ * @throws IOException
+ */
+ public void appendFileContent(File file, String content) throws IOException {
+ appendFileContent(file, new String(content), true);
+ }
+
+ /**
+ * Appends content to given file.
+ *
+ * @param file
+ * @param content
+ * @param append
+ * if true, then bytes will be written to the end of the file
+ * rather than the beginning
+ * @throws IOException
+ */
+ public void appendFileContent(File file, byte[] content, boolean append)
+ throws IOException {
+ appendFileContent(file, new String(content), append);
+ }
+
+ /**
+ * Appends content to given file.
+ *
+ * @param file
+ * @param content
+ * @param append
+ * if true, then bytes will be written to the end of the file
+ * rather than the beginning
+ * @throws IOException
+ */
+ public void appendFileContent(File file, String content, boolean append)
+ throws IOException {
+ FileWriter fw = new FileWriter(file, append);
+ fw.append(content);
+ fw.close();
+ }
+
+ /**
* Checks if a file with the given path exists in the HEAD tree
+ *
* @param path
* @return true if the file exists
* @throws IOException
@@ -234,10 +411,22 @@ public class TestRepository {
if (pLen > pfxLen)
return path.substring(pfxLen);
else if (path.length() == pfxLen - 1)
- return ""; //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
return null;
}
+ public IFile getIFile(IProject project, File file) throws CoreException {
+ String relativePath = getRepoRelativePath(file.getAbsolutePath());
+
+ String quotedProjectName = Pattern.quote(project.getName());
+ relativePath = relativePath.replaceFirst(quotedProjectName, "");
+
+ IFile iFile = project.getFile(relativePath);
+ iFile.refreshLocal(0, null);
+
+ return iFile;
+ }
+
public void dispose() {
repository.close();
repository = null;
@@ -245,6 +434,7 @@ public class TestRepository {
/**
* Connect a project to this repository
+ *
* @param project
* @throws CoreException
*/
@@ -253,4 +443,19 @@ public class TestRepository {
this.getRepository().getDirectory());
op.execute(null);
}
+
+ /**
+ * Disconnects provider from project
+ *
+ * @param project
+ * @throws CoreException
+ */
+ public void disconnect(IProject project) throws CoreException {
+ Collection<IProject> projects = Collections.singleton(project
+ .getProject());
+ DisconnectProviderOperation disconnect = new DisconnectProviderOperation(
+ projects);
+ disconnect.execute(null);
+ }
+
}

Back to the top