import org.eclipse.jgit.treewalk.filter.TreeFilter;
public class TreeWalkBasicDiffTest extends RepositoryTestCase {
public void testMissingSubtree_DetectFileAdded_FileModified()
throws Exception {
final ObjectWriter ow = new ObjectWriter(db);
final ObjectId aFileId = ow.writeBlob("a".getBytes());
final ObjectId bFileId = ow.writeBlob("b".getBytes());
final ObjectId cFileId1 = ow.writeBlob("c-1".getBytes());
final ObjectId cFileId2 = ow.writeBlob("c-2".getBytes());
// Create sub-a/empty, sub-c/empty = hello.
final ObjectId oldTree;
{
final Tree root = new Tree(db);
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(ow.writeTree(subA));
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId1);
subC.setId(ow.writeTree(subC));
}
oldTree = ow.writeTree(root);
}
// Create sub-a/empty, sub-b/empty, sub-c/empty.
final ObjectId newTree;
{
final Tree root = new Tree(db);
{
final Tree subA = root.addTree("sub-a");
subA.addFile("empty").setId(aFileId);
subA.setId(ow.writeTree(subA));
}
{
final Tree subB = root.addTree("sub-b");
subB.addFile("empty").setId(bFileId);
subB.setId(ow.writeTree(subB));
}
{
final Tree subC = root.addTree("sub-c");
subC.addFile("empty").setId(cFileId2);
subC.setId(ow.writeTree(subC));
}
newTree = ow.writeTree(root);
}
final TreeWalk tw = new TreeWalk(db);
tw.reset(new ObjectId[] { oldTree, newTree });
tw.setRecursive(true);