簡體   English   中英

如何使用SVN工具包從SVN中刪除文件

[英]How to delete files from SVN using SVN kit jar

我需要使用svn kit jar刪除svn存儲庫中的文件。

我試過了

SVNFileUtil.deleteFile(new File("URL"));

它不會拋出任何錯誤。 但是我無法刪除我在url中提供的文件。

我的代碼:

       repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));

       //create authentication data
        ISVNAuthenticationManager authManager =
           SVNWCUtil.createDefaultAuthenticationManager(
                   prop.getProperty("SVNusername"), 
                   prop.getProperty("SVNpassword"));
              repository.setAuthenticationManager(authManager);

        //need to identify latest revision
        long latestRevision = repository.getLatestRevision();
        System.out.println("Repository Latest Revision: " + latestRevision);

        //create client manager and set authentication
        SVNClientManager ourClientManager = SVNClientManager.newInstance();
        ourClientManager.setAuthenticationManager(authManager);
        //use SVNUpdateClient to do the export
        SVNCommitClient commitClient = ourClientManager.getCommitClient();
        commitClient.setIgnoreExternals(false);
   SVNFileUtil.deleteFile(new File(urln));
       SVNCommitClient client = new SVNCommitClient(authManager, null);

       SVNCommitInfo info;

@manuelcr是對的,也可以使用高級代碼:

    final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
    try {
        final SvnRemoteDelete remoteDelete = svnOperationFactory.createRemoteDelete();
        remoteDelete.setSingleTarget(SvnTarget.fromURL(fileUrl));
        remoteDelete.setCommitMessage("Delete a file from the repository");
        final SVNCommitInfo commitInfo = remoteDelete.run();
        if (commitInfo != null) {
            final long newRevision = commitInfo.getNewRevision();
            System.out.println("Removed a file, revision " + newRevision + " created");
        }
    } finally {
        svnOperationFactory.dispose();
    }

你嘗試過使用CommitEditor嗎?

此鏈接中,您將了解如何從SVNRepository獲取一個並使用它來刪除條目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM