| Summary: | NPE invoking ResetCommand in a new repository | ||
|---|---|---|---|
| Product: | [Technology] JGit | Reporter: | John Arthorne <john.arthorne> |
| Component: | JGit | Assignee: | Christian Halstrick <christian.halstrick> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | minor | ||
| Priority: | P3 | CC: | caniszczyk, christian.halstrick, remy.suen |
| Version: | unspecified | ||
| Target Milestone: | 1.1-M3 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 339609 | ||
|
Description
John Arthorne
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. |