aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2013-03-14 11:50:48 (EDT)
committerRobin Stocker2013-03-20 19:15:51 (EDT)
commit290b13bbceeec941b4e5e877732b17475f0d46a5 (patch)
treeb7a5cee60cbd44373a5d6235aa4bea2ed4486afb
parente7240dac5aa9ff4c3d9088e635ccfb085bb7ab25 (diff)
downloadegit-290b13bbceeec941b4e5e877732b17475f0d46a5.zip
egit-290b13bbceeec941b4e5e877732b17475f0d46a5.tar.gz
egit-290b13bbceeec941b4e5e877732b17475f0d46a5.tar.bz2
[sync] Accurate revisions for remote and ancestorrefs/changes/54/10654/4
This removes two unused (and outdated) tests in GitResourceVariantTreeSubscriberTest. The third one was removed since it was not testing what was advertised: it mocked a use case where the user was synchronizing a branch with only one commit with a master that also had a single commit, that thus acted as both the "remote" _and_ "common ancestor" of the synchronization. What we want is a use case where all three revisions are distinct. Bug: 393294 Change-Id: I69d4a53e23b7afe916a30b873aada13a6931f4c8 Signed-off-by: Robin Stocker <robin@nibor.org>
-rwxr-xr-xorg.eclipse.egit.core.test/src/org/eclipse/egit/core/synchronize/GitResourceVariantTreeSubscriberTest.java205
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java5
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java5
3 files changed, 71 insertions, 144 deletions
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
index 17c9f59..186a527 100755
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2010, 2012 Dariusz Luksza <dariusz@luksza.org> and others.
+ * Copyright (C) 2010, 2013 Dariusz Luksza <dariusz@luksza.org> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -16,200 +16,125 @@ import java.io.File;
import java.io.IOException;
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.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 static final String MASTER = Constants.R_HEADS + Constants.MASTER;
- private Repository repo;
-
- private IProject iProject;
+ private static final String BRANCH = Constants.R_HEADS + "branch";
private TestRepository testRepo;
+ private RevCommit initialCommit;
+
+ private RevCommit commitBranch;
+
+ private RevCommit commitMaster;
+
+ private IFile changedFile;
+
@Before
public void setUp() throws Exception {
super.setUp();
- iProject = project.getProject();
testRepo = new TestRepository(gitDir);
- testRepo.connect(iProject);
- repo = RepositoryMapping.getMapping(iProject).getRepository();
+ testRepo.connect(project.getProject());
+
+ String fileName = "Main.java";
+ File file = testRepo.createFile(project.getProject(), fileName);
+ initialCommit = testRepo.appendContentAndCommit(project.getProject(),
+ file, "class Main {}", "initial commit");
+ changedFile = testRepo.getIFile(project.getProject(), file);
+
+ testRepo.createAndCheckoutBranch(Constants.HEAD, BRANCH);
+ commitBranch = testRepo.appendContentAndCommit(project.getProject(),
+ file, "// test 1", "second commit");
+
+ testRepo.checkoutBranch(MASTER);
+ commitMaster = testRepo.appendContentAndCommit(project.getProject(),
+ file, "// test 2", "third commit");
}
@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);
- testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS
- + "test");
- testRepo.appendContentAndCommit(iProject, file, "// test1",
- "secont commit");
-
- // given
+ public void testSyncMasterAndBranch() throws Exception {
GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(
- Constants.HEAD, Constants.R_HEADS + Constants.MASTER);
+ MASTER, BRANCH);
grvts.init(new NullProgressMonitor());
- IResourceVariantTree baseTree = grvts.getBaseTree();
- // then
- IResourceVariant actual = commonAssertionsForBaseTree(baseTree,
- mainJava);
- assertEquals(commit.abbreviate(7).name() + "... (J. Git)",
- actual.getContentIdentifier());
+ IResourceVariant actualBase = getBaseVariant(grvts, changedFile);
+ IResourceVariant actualRemote = getRemoteVariant(grvts, changedFile);
+
+ assertVariantMatchCommit(actualBase, initialCommit);
+ assertVariantMatchCommit(actualRemote, commitBranch);
}
- /**
- * 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
+ public void testSyncBranchAndMaster() throws Exception {
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());
+ BRANCH, MASTER);
+ grvts.init(new NullProgressMonitor());
+
+ IResourceVariant actualBase = getBaseVariant(grvts, changedFile);
+ IResourceVariant actualRemote = getRemoteVariant(grvts, changedFile);
+
+ assertVariantMatchCommit(actualBase, initialCommit);
+ assertVariantMatchCommit(actualRemote, commitMaster);
}
- /**
- * 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 GitRemoteResource);
- assertEquals(fileId.getName(), resourceVariant.getContentIdentifier());
+ private void assertVariantMatchCommit(IResourceVariant variant,
+ RevCommit commit) {
+ assertTrue(variant instanceof GitRemoteResource);
+ assertEquals(commit, ((GitRemoteResource) variant).getCommitId());
}
private GitResourceVariantTreeSubscriber createGitResourceVariantTreeSubscriber(
String src, String dst) throws IOException {
- GitSynchronizeData gsd = new GitSynchronizeData(repo, src, dst, false);
+ GitSynchronizeData gsd = new GitSynchronizeData(
+ testRepo.getRepository(), 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)
+ private IResourceVariant getBaseVariant(
+ GitResourceVariantTreeSubscriber subscriber, IResource resource)
throws TeamException {
- assertNotNull(baseTree);
- assertTrue(baseTree instanceof GitBaseResourceVariantTree);
- IResourceVariant resourceVariant = baseTree
+ IResourceVariantTree tree = subscriber.getBaseTree();
+ assertNotNull(tree);
+ assertTrue(tree instanceof GitBaseResourceVariantTree);
+ IResourceVariant resourceVariant = tree
.getResourceVariant(resource);
assertNotNull(resourceVariant);
assertTrue(resourceVariant instanceof GitRemoteResource);
return resourceVariant;
}
+ private IResourceVariant getRemoteVariant(
+ GitResourceVariantTreeSubscriber subscriber, IResource resource)
+ throws TeamException {
+ IResourceVariantTree tree = subscriber.getRemoteTree();
+ assertNotNull(tree);
+ assertTrue(tree instanceof GitRemoteResourceVariantTree);
+ IResourceVariant resourceVariant = tree.getResourceVariant(resource);
+ assertNotNull(resourceVariant);
+ assertTrue(resourceVariant instanceof GitRemoteResource);
+ return resourceVariant;
+ }
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
index 0483cc3..954296f 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitBaseResourceVariantTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 IBM Corporation and others.
* 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Dariusz Luksza <dariusz@luksza.org>
+ * Laurent Goubet <laurent.goubet@obeo.fr> - 393294
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
@@ -30,7 +31,7 @@ class GitBaseResourceVariantTree extends GitResourceVariantTree {
@Override
protected RevCommit getCommitId(GitSynchronizeData gsd) {
- return gsd.getDstRevCommit();
+ return gsd.getCommonAncestorRev();
}
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
index 6343054..a56ed1a 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/synchronize/GitRemoteResourceVariantTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 IBM Corporation and others.
* 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Dariusz Luksza <dariusz@luksza.org>
+ * Laurent Goubet <laurent.goubet@obeo.fr> - 393294
*******************************************************************************/
package org.eclipse.egit.core.synchronize;
@@ -30,7 +31,7 @@ class GitRemoteResourceVariantTree extends GitResourceVariantTree {
@Override
protected RevCommit getCommitId(GitSynchronizeData gsd) {
- return gsd.getSrcRevCommit();
+ return gsd.getDstRevCommit();
}
}