summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2011-08-16 15:15:01 +0200
committerChris Aniszczyk <zx@twitter.com>2011-08-21 14:11:00 -0700
commit930875a81a690f732fb5ac26304d6fb212aa2582 (patch)
tree1aaff8a6cd9b28c00415303837776dfe219d92ce /org.eclipse.jgit.test
parent9952223e0645fd7a8cddc6093a7f449c6390238d (diff)
downloadjgit-930875a81a690f732fb5ac26304d6fb212aa2582.tar.gz
jgit-930875a81a690f732fb5ac26304d6fb212aa2582.zip
Throw JGit exception when ResetCommand got wrong ref
If the ResetCommand should reset to a invalid ref (e.g. HEAD in a repo whithout a single commit) it was throwing an NPE. This is fixed now by throwing a JGitInternalExcpeption. It would be nicer if we could throw a InvalidRefException, but this would modify our API. Bug: 339610 Change-Id: Iffcb4f2cca9f702176471d93c3a71e5cb3e700b1 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java17
1 files changed, 17 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 e6d689a18a..f10aaf52e1 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
@@ -46,6 +46,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -157,6 +158,22 @@ public class ResetCommandTest extends RepositoryTestCase {
}
@Test
+ public void testResetToNonexistingHEAD() throws JGitInternalException,
+ AmbiguousObjectException, IOException {
+
+ // create a file in the working tree of a fresh repo
+ git = new Git(db);
+ writeTrashFile("f", "content");
+
+ try {
+ git.reset().setRef(Constants.HEAD).call();
+ fail("Expected JGitInternalException didn't occur");
+ } catch (JGitInternalException e) {
+ // got the expected exception
+ }
+ }
+
+ @Test
public void testSoftReset() throws JGitInternalException,
AmbiguousObjectException, IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,