|
Re: How to get content of files with JGIT [message #1744392 is a reply to message #1744341] |
Mon, 26 September 2016 13:02 |
Christian Halstrick Messages: 274 Registered: July 2009 |
Senior Member |
|
|
Try adding index and workingtree iterators to the walk. To get real content you can ask objectdb with the oid for commit and index. But for workingtree content you need to use java File io to read content from disk
public class ListWTIndexHEAD {
public static void main(String args[]) throws IOException, GitAPIException, JGitInternalException {
Git r = Git.open(new File(args[0]));
RevWalk rw = new RevWalk(r.getRepository());
try (TreeWalk tw = new TreeWalk(r.getRepository())) {
RevCommit commitToCheck = rw.parseCommit(r.getRepository().resolve("HEAD"));
tw.addTree(commitToCheck.getTree());
tw.addTree(new DirCacheIterator(r.getRepository().readDirCache()));
tw.addTree(new FileTreeIterator(r.getRepository()));
tw.setRecursive(true);
while (tw.next()) {
System.out.printf(
"path: %s, Commit(mode/oid): %s/%s, Index(mode/oid): %s/%s, Workingtree(mode/oid): %s/%s\n",
tw.getPathString(), tw.getFileMode(0), tw.getObjectId(0), tw.getFileMode(1), tw.getObjectId(1),
tw.getFileMode(2), tw.getObjectId(2));
}
}
}
}
Ciao
Chris
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03833 seconds