如何使用SVN工具包jar从SVN删除文件

问题描述 投票:0回答:3

我需要使用 svn kit jar 删除 svn 存储库中的文件。

我试过了

SVNFileUtil.deleteFile(new File("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;
java svn svnkit
3个回答
3
投票

@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();
    }


0
投票
我用 svnkit 删除文件的变体:

final ISVNAuthenticationManager authManager = ... final SVNClientManager clientManager = ... SVNCommitClient svnCommitClient = clientManager.getCommitClient(); SVNWCClient wcClient = clientManager.getWCClient(); for (File file : filesToDelete) { wcClient.doDelete(file, true, false); } File[] filesToCommitArray = filesToDelete.toArray(new File[0]); SVNCommitInfo svnCommitInfo = svnCommitClient.doCommit(filesToCommitArray, false, "Your commit message", null, null, false, false, SVNDepth.INFINITY);
    
© www.soinside.com 2019 - 2024. All rights reserved.