Search in sources :

Example 16 with EmptyTreeIterator

use of org.eclipse.jgit.treewalk.EmptyTreeIterator in project egit by eclipse.

the class RemoveCommand method isTracked.

private boolean isTracked(File file, Repository repo) throws IOException {
    ObjectId objectId = repo.resolve(Constants.HEAD);
    RevTree tree;
    try (RevWalk rw = new RevWalk(repo);
        TreeWalk treeWalk = new TreeWalk(repo)) {
        if (objectId != null)
            tree = rw.parseTree(objectId);
        else
            tree = null;
        treeWalk.setRecursive(true);
        if (tree != null)
            treeWalk.addTree(tree);
        else
            treeWalk.addTree(new EmptyTreeIterator());
        treeWalk.addTree(new DirCacheIterator(repo.readDirCache()));
        treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(Repository.stripWorkDir(repo.getWorkTree(), file))));
        return treeWalk.next();
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) EmptyTreeIterator(org.eclipse.jgit.treewalk.EmptyTreeIterator) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Aggregations

EmptyTreeIterator (org.eclipse.jgit.treewalk.EmptyTreeIterator)16 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Git (org.eclipse.jgit.api.Git)6 Test (org.junit.Test)6 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 IOException (java.io.IOException)4 DiffEntry (org.eclipse.jgit.diff.DiffEntry)4 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)4 ArrayList (java.util.ArrayList)3 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)3 DirCacheIterator (org.eclipse.jgit.dircache.DirCacheIterator)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 Repository (org.eclipse.jgit.lib.Repository)2 RevTree (org.eclipse.jgit.revwalk.RevTree)2 AbstractTreeIterator (org.eclipse.jgit.treewalk.AbstractTreeIterator)2 RefModel (com.gitblit.models.RefModel)1