summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorBernard Leach <leachbj@bouncycastle.org>2011-05-18 11:41:18 -0500
committerChris Aniszczyk <caniszczyk@gmail.com>2011-05-18 11:43:57 -0500
commite3c4610c74c3eef0fdf573d45ab4fe0b01d61fe6 (patch)
treece6ffcb492694129734c58fdfbd05ac7bd712421 /org.eclipse.jgit.test/tst
parent557ea857e3b5229379476f1ee4160fcf5b695bbd (diff)
downloadjgit-e3c4610c74c3eef0fdf573d45ab4fe0b01d61fe6.tar.gz
jgit-e3c4610c74c3eef0fdf573d45ab4fe0b01d61fe6.zip
Add tests for change If203ce5
Bug: 344779 Change-Id: I1628984479d93665bf4987d6a4ff8e67ad73eb36 Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java39
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java132
2 files changed, 171 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index f131c9079c..a014071a56 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -54,11 +54,14 @@ import java.io.FileOutputStream;
import java.io.IOException;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
+import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.merge.MergeStrategy;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
@@ -105,6 +108,42 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
}
@Test
+ public void testPullFastForwardWithBranchInSource() throws Exception {
+ PullResult res = target.pull().call();
+ // nothing to update since we don't have different data yet
+ assertTrue(res.getFetchResult().getTrackingRefUpdates().isEmpty());
+ assertEquals(Status.UP_TO_DATE, res.getRebaseResult().getStatus());
+
+ assertFileContentsEqual(targetFile, "Hello world");
+
+ // change the source file
+ writeToFile(sourceFile, "Another change\n\n\n\nFoo");
+ source.add().addFilepattern("SomeFile.txt").call();
+ RevCommit initialCommit = source.commit()
+ .setMessage("Some change in remote").call();
+
+ // modify the source file in a branch
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ writeToFile(sourceFile, "Another change\n\n\n\nBoo");
+ source.add().addFilepattern("SomeFile.txt").call();
+ RevCommit sideCommit = source.commit()
+ .setMessage("Some change in remote").call();
+
+ // modify the source file on master
+ checkoutBranch("refs/heads/master");
+ writeToFile(sourceFile, "More change\n\n\n\nFoo");
+ source.add().addFilepattern("SomeFile.txt").call();
+ source.commit().setMessage("Some change in remote").call();
+
+ // merge side into master
+ MergeResult result = source.merge().include(sideCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+
+ }
+
+ @Test
public void testPullConflict() throws Exception {
PullResult res = target.pull().call();
// nothing to update since we don't have different data yet
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 2b7d0e5caf..9197ac9983 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -54,6 +54,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseCommand.Action;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
@@ -68,6 +69,7 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -156,6 +158,88 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
@Test
+ public void testRebaseFailsCantCherryPickMergeCommits()
+ throws Exception {
+ /**
+ * Create the following commits and then attempt to rebase topic onto
+ * master. This will fail as the cherry-pick list C, D, E an F contains
+ * a merge commit (F).
+ *
+ * <pre>
+ * A - B (master)
+ * \
+ * C - D - F (topic)
+ * \ /
+ * E - (side)
+ * </pre>
+ */
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ RevCommit first = git.commit().setMessage("Add file1").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ // create a topic branch
+ createBranch(first, "refs/heads/topic");
+
+ // update FILE1 on master
+ writeTrashFile(FILE1, "blah");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("updated file1 on master").call();
+
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file3", "more changess");
+ git.add().addFilepattern("file3").call();
+ RevCommit topicCommit = git.commit()
+ .setMessage("update file3 on topic").call();
+
+ // create a branch from the topic commit
+ createBranch(topicCommit, "refs/heads/side");
+
+ // second commit on topic
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("Add file2").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ // switch to side branch and update file2
+ checkoutBranch("refs/heads/side");
+ writeTrashFile("file3", "more change");
+ git.add().addFilepattern("file3").call();
+ RevCommit sideCommit = git.commit().setMessage("update file2 on side")
+ .call();
+
+ // switch back to topic and merge in side
+ checkoutBranch("refs/heads/topic");
+ MergeResult result = git.merge().include(sideCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+
+ try {
+ RebaseResult rebase = git.rebase().setUpstream("refs/heads/master")
+ .call();
+ fail("MultipleParentsNotAllowedException expected: "
+ + rebase.getStatus());
+ } catch (JGitInternalException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testRebaseParentOntoHeadShouldBeUptoDate() throws Exception {
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ RevCommit parent = git.commit().setMessage("parent comment").call();
+
+ writeTrashFile(FILE1, "another change");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("head commit").call();
+
+ RebaseResult result = git.rebase().setUpstream(parent).call();
+ assertEquals(Status.UP_TO_DATE, result.getStatus());
+ }
+
+ @Test
public void testUpToDate() throws Exception {
// create file1 on master
writeTrashFile(FILE1, FILE1);
@@ -1243,4 +1327,52 @@ public class RebaseCommandTest extends RepositoryTestCase {
br.close();
}
}
+
+ @Test
+ public void testFastForwardWithMultipleCommitsOnDifferentBranches()
+ throws Exception {
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ RevCommit first = git.commit().setMessage("Add file1").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ // create a topic branch
+ createBranch(first, "refs/heads/topic");
+
+ // create file2 on master
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ RevCommit second = git.commit().setMessage("Add file2").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ // create side branch
+ createBranch(second, "refs/heads/side");
+
+ // update FILE1 on master
+ writeTrashFile(FILE1, "blah");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("updated file1 on master")
+ .call();
+
+ // switch to side branch and update file2
+ checkoutBranch("refs/heads/side");
+ writeTrashFile("file2", "more change");
+ git.add().addFilepattern("file2").call();
+ RevCommit fourth = git.commit().setMessage("update file2 on side")
+ .call();
+
+ // switch back to master and merge in side
+ checkoutBranch("refs/heads/master");
+ MergeResult result = git.merge().include(fourth.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+
+ // switch back to topic branch and rebase it onto master
+ checkoutBranch("refs/heads/topic");
+ RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ checkFile(new File(db.getWorkTree(), "file2"), "more change");
+ assertEquals(Status.FAST_FORWARD, res.getStatus());
+ }
}