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

时间:2014-03-18 13:18:21

标签: java svn svnkit

我需要使用 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;

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

您是否尝试过使用CommitEditor?

this link中,您有一个关于如何从SVNRepository获取并使用它来删除条目的说明。

相关问题