Posted By

adietish on 08/23/12


Tagged


Versions (?)

RemoveCommand#isTracked


 / Published in: Java
 

how to check if a file is shared with a git repo?

  1. private boolean isTracked(File file, Repository repo) throws IOException {
  2. ObjectId objectId = repo.resolve(Constants.HEAD);
  3. RevTree tree;
  4. if (objectId != null)
  5. tree = new RevWalk(repo).parseTree(objectId);
  6. else
  7. tree = null;
  8.  
  9. TreeWalk treeWalk = new TreeWalk(repo);
  10. treeWalk.setRecursive(true);
  11. if (tree != null)
  12. treeWalk.addTree(tree);
  13. else
  14. treeWalk.addTree(new EmptyTreeIterator());
  15. treeWalk.addTree(new DirCacheIterator(repo.readDirCache()));
  16. treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(
  17. Repository.stripWorkDir(repo.getWorkTree(), file))));
  18. return treeWalk.next();
  19.  
  20. }

Report this snippet  

You need to login to post a comment.