10

我在 wiki 上看不到记录签出的地方。理想情况下,我想检查一个文件“example/folder/file.xml”,如果不仅仅是文件夹......然后当应用程序关闭或以其他方式关闭时,能够提交回对该文件的更改。我该怎么做呢?

4

3 回答 3

20

作为 SVNKit 开发人员,我建议您更喜欢基于 SvnOperationFactory 的新 API。旧 API(基于 SVNClientManager)仍然可以运行,但所有新的 SVN 功能都将仅适用于新 API。

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
    final SvnCheckout checkout = svnOperationFactory.createCheckout();
    checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
    checkout.setSource(SvnTarget.fromURL(url));
    //... other options
    checkout.run();
} finally {
    svnOperationFactory.dispose();
}
于 2013-01-17T19:45:10.367 回答
9

您不能在 Subversion 中签出文件。您必须签出一个文件夹。

要检出包含一个或多个文件的文件夹:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
updateClient.doCheckout(url, destPath, revision, revision,
            isRecursive);

提交以前签出的文件夹:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
ourClientManager.getWCClient().doInfo(wcPath, SVNRevision.HEAD);
ourClientManager.getCommitClient().doCommit
        (new File[] { wcPath }, keepLocks, commitMessage, false, true);
于 2010-08-03T17:47:09.610 回答
0

我还使用了 Dmitry Pavlenko 提出的代码片段,我没有遇到任何问题。但是签出或更新 35 MB 的 repo 结构需要将近 30 分钟。它在我的用例中不可用(只需检查目录结构作为 Web 应用程序的内容/文档/媒体的一部分)。还是我犯了一些错误?

final ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
final SVNURL svnUrl = SVNURL.create(url.getProtocol(), name, url.getHost(), 443, url.getPath(), true);

SVNRepository svnRepo= SVNRepositoryFactory.create(svnUrl);
svnRepo.setAuthenticationManager(authManager);
svnOperationFactory.setAuthenticationManager(authManager);

SVNDirEntry entry = svnRepo.info(".", -1);
long remoteRevision = entry.getRevision();

if (!workingCopyDirectory.exists()) {
    workingCopyDirectory.mkdirs();
}

final SvnCheckout checkout = svnOperationFactory.createCheckout();
checkout.setSource(SvnTarget.fromURL(svnUrl));
checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
remoteRevision = checkout.run();
于 2017-07-15T11:50:36.327 回答