Posted By


adietish on 08/23/12

Tagged


Statistics


Viewed 82 times
Favorited by 0 user(s)

RemoveCommand#isTracked


/ Published in: Java
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.