使用SVNKit检出目录/文件

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

您无法在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); 

作为SVNKit开发人员,我建议您更喜欢基于SvnOperationFactory的新API。 旧的API(基于SVNClientManager)仍然可以运行,但所有新的SVNfunction都只能用于新的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(); } 

我还使用了Dmitry Pavlenko提出的代码片段,我没有遇到任何问题。 但是花了差不多30分钟才结账或更新了35 MB的repo struture。 它在我的用例中是不可用的(只是将目录结构作为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();