summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2010-11-24 09:43:38 +0100
committerChristian Halstrick <christian.halstrick@sap.com>2010-11-24 15:59:08 +0100
commit7e298c9ed538dd8d5207adce3497b4a1df701dc5 (patch)
tree13c9057dc5b7604f9fcb75a348b566b82d934237 /org.eclipse.jgit.test
parentc441380f9cf6a294f6353ff35526a367f950004f (diff)
downloadjgit-7e298c9ed538dd8d5207adce3497b4a1df701dc5.tar.gz
jgit-7e298c9ed538dd8d5207adce3497b4a1df701dc5.zip
Add more tests for rebase and externalized missing Strings
Coverage tests showed that we are missing to test certain areas in the rebase command. Add the missing tests. Change-Id: Ia4a272d26cde7e1861dac30496e4b6799fc8187a Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java99
1 files changed, 99 insertions, 0 deletions
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 aee2cc4d84..e3c8a26301 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
@@ -50,6 +50,8 @@ import java.io.InputStreamReader;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
+import org.eclipse.jgit.api.errors.RefNotFoundException;
+import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -82,6 +84,21 @@ public class RebaseCommandTest extends RepositoryTestCase {
refUpdate.link(branchName);
}
+ private void checkoutCommit(RevCommit commit) throws IllegalStateException,
+ IOException {
+ RevWalk walk = new RevWalk(db);
+ RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
+ DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
+ db.lockDirCache(), commit.getTree());
+ dco.setFailOnConflict(true);
+ dco.checkout();
+ walk.release();
+ // update the HEAD
+ RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
+ refUpdate.setNewObjectId(commit);
+ refUpdate.forceUpdate();
+ }
+
public void testFastForwardWithNewFile() throws Exception {
Git git = new Git(db);
@@ -106,6 +123,39 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(Status.UP_TO_DATE, res.getStatus());
}
+ public void testUpToDate() throws Exception {
+ Git git = new Git(db);
+
+ // 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());
+
+ RebaseResult res = git.rebase().setUpstream(first).call();
+ assertEquals(Status.UP_TO_DATE, res.getStatus());
+ }
+
+ public void testUnknownUpstream() throws Exception {
+ Git git = new Git(db);
+
+ // create file1 on master
+ writeTrashFile("file1", "file1");
+ git.add().addFilepattern("file1").call();
+ git.commit().setMessage("Add file1").call();
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+
+ try {
+ git.rebase().setUpstream("refs/heads/xyz")
+ .call();
+ fail("expected exception was not thrown");
+ } catch (RefNotFoundException e) {
+ // expected exception
+ }
+ }
+
public void testConflictFreeWithSingleFile() throws Exception {
Git git = new Git(db);
@@ -142,6 +192,46 @@ public class RebaseCommandTest extends RepositoryTestCase {
db.resolve(Constants.HEAD)).getParent(0));
}
+ public void testDetachedHead() throws Exception {
+ Git git = new Git(db);
+
+ // create file1 on master
+ File theFile = writeTrashFile("file1", "1\n2\n3\n");
+ git.add().addFilepattern("file1").call();
+ RevCommit second = git.commit().setMessage("Add file1").call();
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ // change first line in master and commit
+ writeTrashFile("file1", "1master\n2\n3\n");
+ checkFile(theFile, "1master\n2\n3\n");
+ git.add().addFilepattern("file1").call();
+ RevCommit lastMasterChange = git.commit()
+ .setMessage("change file1 in master").call();
+
+ // create a topic branch based on second commit
+ createBranch(second, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ // we have the old content again
+ checkFile(theFile, "1\n2\n3\n");
+
+ assertTrue(new File(db.getWorkTree(), "file1").exists());
+ // change third line in topic branch
+ writeTrashFile("file1", "1\n2\n3\ntopic\n");
+ git.add().addFilepattern("file1").call();
+ RevCommit topicCommit = git.commit()
+ .setMessage("change file1 in topic").call();
+ checkoutBranch("refs/heads/master");
+ checkoutCommit(topicCommit);
+ assertEquals(topicCommit.getId().getName(), db.getFullBranch());
+
+ RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
+ assertEquals(Status.OK, res.getStatus());
+ checkFile(theFile, "1master\n2\n3\ntopic\n");
+ assertEquals(lastMasterChange,
+ new RevWalk(db).parseCommit(db.resolve(Constants.HEAD))
+ .getParent(0));
+
+ }
+
public void testFilesAddedFromTwoBranches() throws Exception {
Git git = new Git(db);
@@ -234,6 +324,15 @@ public class RebaseCommandTest extends RepositoryTestCase {
// the first one should be included, so we should have left two picks in
// the file
assertEquals(countPicks(), 2);
+
+ // rebase should not succeed in this state
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ fail("Expected exception was not thrown");
+ } catch (WrongRepositoryStateException e) {
+ // expected
+ }
+
// abort should reset to topic branch
res = git.rebase().setOperation(Operation.ABORT).call();
assertEquals(res.getStatus(), Status.ABORTED);