如何使用SVNKit在SVN中提交特定文件而不是整个目录?
提交整个目录的代码:
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager((String) session.getAttribute("USERNAME"), (String) session.getAttribute("PASSWORD"));
repository.setAuthenticationManager(authManager);
SVNClientManager ourClientManager = SVNClientManager.newInstance(null,repository.getAuthenticationManager());
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.doUpdate(wcDir, SVNRevision.HEAD, SVNDepth.INFINITY, false, false);
ourClientManager.getWCClient().doInfo(wcDir, SVNRevision.HEAD);
SVNCommitInfo s1=ourClientManager.getCommitClient().doCommit(new File[] {wcDir}, true, "From Code", svnProperties.getRegularProperties(), null, true, false, SVNDepth.INFINITY);
答案 0 :(得分:7)
如果您将SVNKit用作库,请使用以下代码:
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
final SvnCommit commit = svnOperationFactory.createCommit();
commit.setSingleTarget(SvnTarget.fromFile(file));
commit.setCommitMessage("Commit message");
final SVNCommitInfo commitInfo = commit.run();
} finally {
svnOperationFactory.dispose();
}
如果您使用SVNKit作为命令行工具,请运行:
$ jsvn commit path/to/file
<强>更新强> 这是1.3.x的代码
final SVNClientManager clientManager = SVNClientManager.newInstance();
try {
final SVNCommitClient commitClient = clientManager.getCommitClient();
final SVNCommitInfo commitInfo = commitClient.doCommit(new File[]{file}, false, "Commit message", null, null, false, false, SVNDepth.INFINITY);
} finally {
clientManager.dispose();
}