]> source.dussan.org Git - jgit.git/commitdiff
Add test for reflog part of ResetCommand 14/3414/2
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Wed, 4 May 2011 22:26:39 +0000 (00:26 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Fri, 13 May 2011 21:45:54 +0000 (23:45 +0200)
The reflog message fix was done in
I4f1c3cd6b2cf543be213f061afb94223062dde51

Change-Id: I44817ccf4bf226ed3e4ce6fb2d923e88788221dd
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java

index b886432a3933e1326baadb2f72c0888359389a5c..578b98170f2b5c52da8ea0dcffbb4e377714b008 100644 (file)
@@ -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());
        }
 
        /**