我想使用 SVNDiffClient 来获取 wc 本地更改,相当于“svn diff -rBASE”,这正是本示例应该做的。
但是,运行示例中的代码会抛出“org.tmatesoft.svn.core.SVNException: svn: 至少一个修订版必须是非本地的,以用于挂钩差异”,这正是文档所说的。
我希望能够在不访问服务器的情况下将 WORKING 与 BASE 进行比较,看看是否有任何变化。这可以使用 SVNKit 完成吗?
您可以使用新的 API:
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final SvnDiff diff = svnOperationFactory.createDiff();
diff.setSources(SvnTarget.fromFile(workingCopyDirectory, SVNRevision.BASE), SvnTarget.fromFile(workingCopyDirectory, SVNRevision.WORKING));
diff.setOutput(byteArrayOutputStream);
diff.run();
您也可以使用旧 API:
final SVNClientManager clientManager = SVNClientManager.newInstance();
try {
final SVNDiffClient diffClient = clientManager.getDiffClient();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
diffClient.doDiff(workingCopyDirectory, SVNRevision.BASE, workingCopyDirectory, SVNRevision.WORKING, SVNDepth.INFINITY, false, outputStream, null);
System.out.println(outputStream);
} finally {
clientManager.dispose();
}