diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2016-07-15 00:13:01 +0200 |
---|---|---|
committer | Andrey Loskutov <loskutov@gmx.de> | 2016-08-17 08:56:03 -0400 |
commit | 13f0db25f272e29b607c5b0e01a3b0d612731794 (patch) | |
tree | 32f1ab0541031d1fecf2f313ed08773394e3d40a /org.eclipse.jgit.test | |
parent | 0b4751e805e3792403c5e3b39aa4f5555081991d (diff) | |
download | jgit-13f0db25f272e29b607c5b0e01a3b0d612731794.tar.gz jgit-13f0db25f272e29b607c5b0e01a3b0d612731794.zip |
Enhance ResetCommand to allow disabling reflog update
This will be used by EGit for implementing commit amend in the staging
view (see Idcd1efeeee8b3065bae36e285bfc0af24ab1e88f).
Change-Id: Ice9ebbb1c0c3314c679f4db40cdd3664f61c27c3
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/ResetCommandTest.java | 40 |
1 files changed, 40 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 a4a699ef22..ba51881ffd 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 @@ -157,6 +157,28 @@ public class ResetCommandTest extends RepositoryTestCase { } @Test + public void testHardResetReflogDisabled() throws Exception { + setupRepository(); + ObjectId prevHead = db.resolve(Constants.HEAD); + ResetCommand reset = git.reset(); + assertSameAsHead(reset.setMode(ResetType.HARD) + .setRef(initialCommit.getName()).disableRefLog(true).call()); + assertTrue("reflog should be disabled", reset.isReflogDisabled()); + // check if HEAD points to initial commit now + ObjectId head = db.resolve(Constants.HEAD); + assertEquals(initialCommit, head); + // check if files were removed + assertFalse(indexFile.exists()); + assertTrue(untrackedFile.exists()); + // fileInIndex must no longer be in HEAD and in the index + String fileInIndexPath = indexFile.getAbsolutePath(); + assertFalse(inHead(fileInIndexPath)); + assertFalse(inIndex(indexFile.getName())); + assertReflogDisabled(head); + assertEquals(prevHead, db.readOrigHead()); + } + + @Test public void testHardResetWithConflicts_DoOverWriteUntrackedFile() throws JGitInternalException, AmbiguousObjectException, IOException, GitAPIException { @@ -562,6 +584,24 @@ public class ResetCommandTest extends RepositoryTestCase { .getName()); } + private void assertReflogDisabled(ObjectId head) + throws IOException { + // Check the reflog for HEAD + String actualHeadMessage = db.getReflogReader(Constants.HEAD) + .getLastEntry().getComment(); + String expectedHeadMessage = "commit: adding a.txt and dir/b.txt"; + assertEquals(expectedHeadMessage, actualHeadMessage); + assertEquals(head.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 = "commit: adding a.txt and dir/b.txt"; + assertEquals(expectedMasterMessage, actualMasterMessage); + assertEquals(head.getName(), db.getReflogReader(Constants.HEAD) + .getLastEntry().getOldId().getName()); + } /** * Checks if a file with the given path exists in the HEAD tree * |