Community
Participate
Working Groups
1) Create a new repository 2) Perform AddCommand to add a file to the index 3) Perform ResetCommand to remove the file from index NPE occurs. It is trying to obtain the id of the last commit, but since there are no commits it gets an NPE: java.lang.NullPointerException at org.eclipse.jgit.lib.ObjectIdSubclassMap.index(ObjectIdSubclassMap.java:213) at org.eclipse.jgit.lib.ObjectIdSubclassMap.get(ObjectIdSubclassMap.java:89) at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:809) at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:724) at org.eclipse.jgit.api.ResetCommand.call(ResetCommand.java:149) at org.eclipse.orion.server.git.servlets.GitIndexHandlerV1.handlePost(GitIndexHandlerV1.java:130)
If you want to remove the file from the index using the ResetCommand in this case is not correct since the ResetCommand tries to reset the repository to the last commit, which does not exist (as you already said). Also on the git command line reset would not work in this case, but fail with an error message, saying that HEAD doesn't exist. If you just want to remove the file from the index you should use (as in git command line) the rm command. File tmpDir = new File(System.getProperty("java.io.tmpdir"), "tmp" + System.currentTimeMillis()); Git repo = Git.init().setDirectory(new File(tmpDir, "repo1")).call(); new FileWriter(new File(repo.getRepository().getWorkTree(), "f.txt")) .write("hello world"); repo.add().addFilepattern("f.txt").call(); repo.rm().addFilepattern("f.txt").call(); But I agree that your usage of resetCommand should not result in NPE. We should throw a better exception.
Fixed in master.