1

如何使用 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);
4

1 回答 1

8

如果您使用 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();
}
于 2013-03-20T12:22:05.157 回答