gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:03:23 26 4
gpt4 key购买 nike

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

最佳答案

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

关于java - 如何使用 SVN 工具包 jar 从 SVN 中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com