1

如何访问 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 的实际文件内容?

4

0 回答 0