summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChris Aniszczyk <caniszczyk@gmail.com>2011-05-13 18:05:58 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-05-13 18:05:58 -0400
commit24ce43de0c266750a0856ca3549b895a8bb44f44 (patch)
treea653c7e5c6f70e425c6190cf1bfa0b335bfc6601 /org.eclipse.jgit.test
parentc22eab4948fbeaa26f6b892b5061bb174496d1ca (diff)
parente9311e526c1ddff33cb7fc09578909ae9441ecd6 (diff)
downloadjgit-24ce43de0c266750a0856ca3549b895a8bb44f44.tar.gz
jgit-24ce43de0c266750a0856ca3549b895a8bb44f44.zip
Merge "Add test for reflog part of ResetCommand"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index b886432a39..578b98170f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -116,6 +117,7 @@ public class ResetCommandTest extends RepositoryTestCase {
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
setupRepository();
+ ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.HARD).setRef(initialCommit.getName())
.call();
// check if HEAD points to initial commit now
@@ -128,6 +130,7 @@ public class ResetCommandTest extends RepositoryTestCase {
String fileInIndexPath = indexFile.getAbsolutePath();
assertFalse(inHead(fileInIndexPath));
assertFalse(inIndex(indexFile.getName()));
+ assertReflog(prevHead, head);
}
@Test
@@ -136,6 +139,7 @@ public class ResetCommandTest extends RepositoryTestCase {
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
setupRepository();
+ ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.SOFT).setRef(initialCommit.getName())
.call();
// check if HEAD points to initial commit now
@@ -148,6 +152,7 @@ public class ResetCommandTest extends RepositoryTestCase {
String fileInIndexPath = indexFile.getAbsolutePath();
assertFalse(inHead(fileInIndexPath));
assertTrue(inIndex(indexFile.getName()));
+ assertReflog(prevHead, head);
}
@Test
@@ -156,6 +161,7 @@ public class ResetCommandTest extends RepositoryTestCase {
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
WrongRepositoryStateException {
setupRepository();
+ ObjectId prevHead = db.resolve(Constants.HEAD);
git.reset().setMode(ResetType.MIXED).setRef(initialCommit.getName())
.call();
// check if HEAD points to initial commit now
@@ -168,6 +174,33 @@ public class ResetCommandTest extends RepositoryTestCase {
String fileInIndexPath = indexFile.getAbsolutePath();
assertFalse(inHead(fileInIndexPath));
assertFalse(inIndex(indexFile.getName()));
+
+ assertReflog(prevHead, head);
+ }
+
+ private void assertReflog(ObjectId prevHead, ObjectId head)
+ throws IOException {
+ // Check the reflog for HEAD
+ String actualHeadMessage = db.getReflogReader(Constants.HEAD)
+ .getLastEntry().getComment();
+ String expectedHeadMessage = head.getName() + ": updating HEAD";
+ assertEquals(expectedHeadMessage, actualHeadMessage);
+ assertEquals(head.getName(), db.getReflogReader(Constants.HEAD)
+ .getLastEntry().getNewId().getName());
+ assertEquals(prevHead.getName(), db
+ .getReflogReader(Constants.HEAD).getLastEntry().getOldId()
+ .getName());
+
+ // The reflog for master contains the same as the one for HEAD
+ String actualMasterMessage = db.getReflogReader("refs/heads/master")
+ .getLastEntry().getComment();
+ String expectedMasterMessage = head.getName() + ": updating HEAD"; // yes!
+ assertEquals(expectedMasterMessage, actualMasterMessage);
+ assertEquals(head.getName(), db.getReflogReader(Constants.HEAD)
+ .getLastEntry().getNewId().getName());
+ assertEquals(prevHead.getName(),
+ db.getReflogReader("refs/heads/master").getLastEntry()
+ .getOldId().getName());
}
/**