summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java6
2 files changed, 23 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,
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
index 05f59950ff..cd50ba07da 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
@@ -151,6 +151,12 @@ public class ResetCommand extends GitCommand<Ref> {
final ObjectId commitId;
try {
commitId = repo.resolve(ref);
+ if (commitId == null) {
+ // @TODO throw an InvalidRefNameException. We can't do that
+ // now because this would break the API
+ throw new JGitInternalException("Invalid ref " + ref
+ + " specified");
+ }
} catch (IOException e) {
throw new JGitInternalException(
MessageFormat.format(JGitText.get().cannotRead, ref),