繁体   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