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;
assertReflog(prevHead, head);
}
+ @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,
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),