summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorMikael Karlsson <mmmicke@gmail.com>2012-05-16 18:34:38 +0200
committerChris Aniszczyk <zx@twitter.com>2012-11-16 12:51:35 -0800
commitfa5231191d530afb24810080e89990913c8e8054 (patch)
treeb6a8a55481c7f7110249f92dfbf35a470b0f2077 /org.eclipse.jgit.test/tst
parent58dd2868485352de558121b7397e8a9ea2901f82 (diff)
downloadjgit-fa5231191d530afb24810080e89990913c8e8054.tar.gz
jgit-fa5231191d530afb24810080e89990913c8e8054.zip
Add support for pull with --rebase and --no-rebase
Bug: 394501 Change-Id: I697e2fc82a46c03762111eb1de93e673a2643b4f Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java70
1 files changed, 70 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 2c1eb768bd..2f2faf8228 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
@@ -44,6 +44,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -58,11 +59,14 @@ import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
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.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
@@ -226,6 +230,72 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
.getRepository().getRepositoryState());
}
+ @Test
+ public void testPullFastForwardWithLocalCommitAndRebaseFlagSet() throws Exception {
+ final String SOURCE_COMMIT_MESSAGE = "Source commit message for rebase flag test";
+ final String TARGET_COMMIT_MESSAGE = "Target commit message for rebase flag test";
+
+ assertFalse(SOURCE_COMMIT_MESSAGE.equals(TARGET_COMMIT_MESSAGE));
+
+ final String SOURCE_FILE_CONTENTS = "Source change";
+ final String NEW_FILE_CONTENTS = "New file from target";
+
+ // make sure the config for target says we should pull with merge
+ // we will override this later with the setRebase method
+ StoredConfig targetConfig = dbTarget.getConfig();
+ targetConfig.setBoolean("branch", "master", "rebase", false);
+ targetConfig.save();
+
+ // create commit in source
+ writeToFile(sourceFile, SOURCE_FILE_CONTENTS);
+ source.add().addFilepattern(sourceFile.getName()).call();
+ source.commit().setMessage(SOURCE_COMMIT_MESSAGE).call();
+
+ // create commit in target, not conflicting with the new commit in source
+ File newFile = new File(dbTarget.getWorkTree().getPath() + "/newFile.txt");
+ writeToFile(newFile, NEW_FILE_CONTENTS);
+ target.add().addFilepattern(newFile.getName()).call();
+ target.commit().setMessage(TARGET_COMMIT_MESSAGE).call();
+
+ // verify that rebase is set to false in the config
+ assertFalse(targetConfig.getBoolean("branch", "master", "rebase", true));
+
+ // pull with rebase - local commit in target should be on top
+ PullResult pullResult = target.pull().setRebase(true).call();
+
+ // make sure pull is considered successful
+ assertTrue(pullResult.isSuccessful());
+
+ // verify rebase result is ok
+ RebaseResult rebaseResult = pullResult.getRebaseResult();
+ assertNotNull(rebaseResult);
+ assertNull(rebaseResult.getFailingPaths());
+ assertEquals(Status.OK, rebaseResult.getStatus());
+
+ // Get the HEAD and HEAD~1 commits
+ Repository targetRepo = target.getRepository();
+ RevWalk revWalk = new RevWalk(targetRepo);
+ ObjectId headId = targetRepo.resolve(Constants.HEAD);
+ RevCommit root = revWalk.parseCommit(headId);
+ revWalk.markStart(root);
+ // HEAD
+ RevCommit head = revWalk.next();
+ // HEAD~1
+ RevCommit beforeHead = revWalk.next();
+
+ // verify the commit message on the HEAD commit
+ assertEquals(TARGET_COMMIT_MESSAGE, head.getFullMessage());
+ // verify the commit just before HEAD
+ assertEquals(SOURCE_COMMIT_MESSAGE, beforeHead.getFullMessage());
+
+ // verify file states
+ assertFileContentsEqual(sourceFile, SOURCE_FILE_CONTENTS);
+ assertFileContentsEqual(newFile, NEW_FILE_CONTENTS);
+ // verify repository state
+ assertEquals(RepositoryState.SAFE, target
+ .getRepository().getRepositoryState());
+ }
+
@Override
@Before
public void setUp() throws Exception {