[英]How to delete files from SVN using SVN kit jar
I need to delete a file in the svn repository by using svn kit jar . 我需要使用svn kit jar删除svn存储库中的文件。
I tried 我试过了
SVNFileUtil.deleteFile(new File("URL"));
It does not throw any error. 它不会抛出任何错误。 but am not able to delete the file which i given in url. 但是我无法删除我在url中提供的文件。
my code: 我的代码:
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 is right, and alternatively you can use high level code: @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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.