*/
package org.eclipse.jgit.api;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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
String fileInIndexPath = indexFile.getAbsolutePath();
assertFalse(inHead(fileInIndexPath));
assertFalse(inIndex(indexFile.getName()));
+ assertReflog(prevHead, head);
}
@Test
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
String fileInIndexPath = indexFile.getAbsolutePath();
assertFalse(inHead(fileInIndexPath));
assertTrue(inIndex(indexFile.getName()));
+ assertReflog(prevHead, head);
}
@Test
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
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());
}
/**