我需要使用 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();
}
您尝试过使用 CommitEditor 吗?
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);