Issue with handling TreeWalk
kumarp149 opened this issue · comments
kumarp149 commented
Version
6.10.0
Operating System
Linux/Unix
Bug description
Consider the following test case.
Following are the steps that are done in the code:
- create, add and commit a file (any file, I chose binary)
- delete the file and commit it again
- Trying iterating the tree walk which is created on top of second commit
@Test
public void RevTreeParsingTest() throws Exception{
Git git = Git.wrap(db);
String binaryFile = "file.bin";
writeTrashFile(binaryFile, "\u0000\u0001");
git.add().addFilepattern(binaryFile).call();
git.commit().setMessage("BASE COMMIT").call();
deleteTrashFile(binaryFile);
git.add().addFilepattern(binaryFile).call();
RevCommit commit2 = git.commit().setMessage("COMMIT-1").call();
RevTree tree = commit2.getTree();
TreeWalk tw = new TreeWalk(git.getRepository());
tw.addTree(tree);
boolean found = false;
while(tw.next()){
if (tw.getPathString().equals(binaryFile)){
found = true;
break;
}
}
assert !found;
}
Actual behavior
The test case is failing
Expected behavior
The test case should pass (i.e. the deleted path should not be present in the treewalk)
Relevant log output
No response
Other information
No response
Matthias Sohn commented
Use git.rm().addFilepattern(binaryFile).call()
instead of
deleteTrashFile(binaryFile);
git.add().addFilepattern(binaryFile).call();