2010-08-03 142 views
8

我無法在wiki上看到檢出文件的位置。理想情況下,我想檢出一個文件「example/folder/file.xml」,如果不是文件夾......然後在應用程序關閉或其他情況下能夠重新提交對該文件的更改。我該怎麼做呢?使用SVNKit檢出目錄/文件

回答

8

你不能簽出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); 
+1

+1非常有用的答案。另外,如果你想**導出**文件,那麼你可以使用['updateClient.doExport(url,destPath,revision,revision,eolStyle,force,isRecursive)'](http://svnkit.com /javadoc/org/tmatesoft/svn/core/wc/SVNUpdateClient.html#doExport%28org.tmatesoft.svn.core.SVNURL,%20java.io.File,%20org.tmatesoft.svn.core.wc.SVNRevision,% 20org.tmatesoft.svn.core.wc.SVNRevision,%20java.lang.String,%20boolean,%20boolean%29) – 2012-06-27 16:18:10

+0

列出的doExport超載在SVNKit 1.7.5-v1中已棄用。相反,我使用了以下重載:'updateClient.doCheckout(url,destPath,SVNRevision.HEAD,SVNRevision.HEAD,SVNDepth.INFINITY,true);' – jbandi 2012-09-20 19:37:09

+0

使用上面的代碼我得到一個警告「方法doCheckout(SVNURL ,File,SVNRevision,SVNRevision,boolean)從類型SVNUpdateClient被棄用「...任何想法使用哪種方法,而不是doCheckout? – Lucy 2014-10-09 11:29:05

18

由於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(); 
} 
+0

所以我們必須聲明workingCopyDirectory爲「文件workingCopyDirectory =新文件(」/ home/lucy「);」 ??? – Lucy 2014-10-09 11:35:38

+0

是的,如果你想讓你的工作副本目錄在/ home/lucy – 2014-10-09 16:15:30

+0

ok ..我有另外一個疑問...... SvnOperationFactory會複製一個文件夾還有存儲在一個particukar SVN路徑中的文件或只是文件? – Lucy 2014-10-10 12:16:05

0

我也使用了Dmitry Pavlenko提出的代碼片段,我沒有問題。 但花了將近30分鐘結帳或更新35 MB的回購結構。 這不適用於我的用例(只需將目錄結構作爲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(); 
+0

我有同樣的問題,需要永久完成...必須缺少一個參數。你有沒有解決它? – 2017-11-22 13:58:56