如何在gitblit钩子中访问更改的文件?当我进行推送时,我需要获取所有已更改文件的列表并对它们进行一些测试,我该如何实现?
我做了以下事情:
RevWalk rw = new RevWalk(repository);
ObjectId head = repository.resolve(Constants.HEAD);
RevCommit commit = rw.parseCommit(head);
RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
for (DiffEntry diff : diffs) {
System.out.println(MessageFormat.format("({0} {1} {2}", diff.getChangeType().name(), diff.getNewMode().getBits(), diff.getNewPath()));
}
接下来我该怎么做才能获得DiffEntry的实际文件内容?