eclipse-jgit / jgit

JGit, the Java implementation of git

Home Page:https://www.eclipse.org/jgit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with handling TreeWalk

kumarp149 opened this issue · comments

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:

  1. create, add and commit a file (any file, I chose binary)
  2. delete the file and commit it again
  3. 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

Use git.rm().addFilepattern(binaryFile).call() instead of

deleteTrashFile(binaryFile);
git.add().addFilepattern(binaryFile).call();