summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMaik Schreiber <blizzy@blizzy.de>2014-06-19 12:54:14 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2014-07-30 16:20:08 +0200
commit7ff1e0d8f56dda85ba2a2224126a1075bda1bcf2 (patch)
tree53d7f37d3a5ba52402cc5213aa661d0a5e438d09 /org.eclipse.jgit.test
parent7b0ee393ba1b5b99aa89c92bb841ef057c2aaa02 (diff)
downloadjgit-7ff1e0d8f56dda85ba2a2224126a1075bda1bcf2.tar.gz
jgit-7ff1e0d8f56dda85ba2a2224126a1075bda1bcf2.zip
Fix RevertCommand to correctly revert multiple commits at once.
The fix is to move the new head commit to the newly-created revert commit, so that additional revert commits will use the correct head. Change-Id: I5de3a9a2a4c276e60af732e9c507cbbdfd1a4652 Signed-off-by: Maik Schreiber <blizzy@blizzy.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
index bb3e7a92e8..060168c673 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
@@ -99,6 +99,8 @@ public class RevertCommandTest extends RepositoryTestCase {
git.revert().include(fixingA).call();
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+
assertTrue(new File(db.getWorkTree(), "b").exists());
checkFile(new File(db.getWorkTree(), "a"),
"first line\nsec. line\nthird line\nfourth line\n");
@@ -124,6 +126,104 @@ public class RevertCommandTest extends RepositoryTestCase {
}
@Test
+ public void testRevertMultiple() throws IOException, JGitInternalException,
+ GitAPIException {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "first\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add first").call();
+
+ writeTrashFile("a", "first\nsecond\n");
+ git.add().addFilepattern("a").call();
+ RevCommit secondCommit = git.commit().setMessage("add second").call();
+
+ writeTrashFile("a", "first\nsecond\nthird\n");
+ git.add().addFilepattern("a").call();
+ RevCommit thirdCommit = git.commit().setMessage("add third").call();
+
+ git.revert().include(thirdCommit).include(secondCommit).call();
+
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+
+ checkFile(new File(db.getWorkTree(), "a"), "first\n");
+ Iterator<RevCommit> history = git.log().call().iterator();
+ RevCommit revertCommit = history.next();
+ String expectedMessage = "Revert \"add second\"\n\n"
+ + "This reverts commit "
+ + secondCommit.getId().getName() + ".\n";
+ assertEquals(expectedMessage, revertCommit.getFullMessage());
+ revertCommit = history.next();
+ expectedMessage = "Revert \"add third\"\n\n"
+ + "This reverts commit " + thirdCommit.getId().getName()
+ + ".\n";
+ assertEquals(expectedMessage, revertCommit.getFullMessage());
+ assertEquals("add third", history.next().getFullMessage());
+ assertEquals("add second", history.next().getFullMessage());
+ assertEquals("add first", history.next().getFullMessage());
+ assertFalse(history.hasNext());
+
+ ReflogReader reader = db.getReflogReader(Constants.HEAD);
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+ reader = db.getReflogReader(db.getBranch());
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+
+ }
+
+ @Test
+ public void testRevertMultipleWithFail() throws IOException,
+ JGitInternalException, GitAPIException {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "first\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add first").call();
+
+ writeTrashFile("a", "first\nsecond\n");
+ git.add().addFilepattern("a").call();
+ RevCommit secondCommit = git.commit().setMessage("add second").call();
+
+ writeTrashFile("a", "first\nsecond\nthird\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("add third").call();
+
+ writeTrashFile("a", "first\nsecond\nthird\nfourth\n");
+ git.add().addFilepattern("a").call();
+ RevCommit fourthCommit = git.commit().setMessage("add fourth").call();
+
+ git.revert().include(fourthCommit).include(secondCommit).call();
+
+ // not SAFE because it failed
+ assertEquals(RepositoryState.REVERTING, db.getRepositoryState());
+
+ checkFile(new File(db.getWorkTree(), "a"), "first\n"
+ + "<<<<<<< master\n" + "second\n" + "third\n" + "=======\n"
+ + ">>>>>>> " + secondCommit.getId().abbreviate(7).name()
+ + " add second\n");
+ Iterator<RevCommit> history = git.log().call().iterator();
+ RevCommit revertCommit = history.next();
+ String expectedMessage = "Revert \"add fourth\"\n\n"
+ + "This reverts commit " + fourthCommit.getId().getName()
+ + ".\n";
+ assertEquals(expectedMessage, revertCommit.getFullMessage());
+ assertEquals("add fourth", history.next().getFullMessage());
+ assertEquals("add third", history.next().getFullMessage());
+ assertEquals("add second", history.next().getFullMessage());
+ assertEquals("add first", history.next().getFullMessage());
+ assertFalse(history.hasNext());
+
+ ReflogReader reader = db.getReflogReader(Constants.HEAD);
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+ reader = db.getReflogReader(db.getBranch());
+ assertTrue(reader.getLastEntry().getComment()
+ .startsWith("revert: Revert \""));
+
+ }
+
+ @Test
public void testRevertDirtyIndex() throws Exception {
Git git = new Git(db);
RevCommit sideCommit = prepareRevert(git);