SVNKit - 修改提交

时间:2012-09-06 09:59:33

标签: java svn svnkit

我使用 SVNKit 库开发 Java 程序,该库负责在版本控制下更新或提交目录。 目录内容可以由我无法控制的另一个程序更改,该程序可以添加,删除或编辑文件,忽略设置颠覆信息。

问题是«我的程序如何知道提交什么»?

由于未添加新文件,我尝试处理rootIirectory的doImport,但它导致SVNException表明该文件已存在于存储库端。

SVNCommitClient cc = cm.getCommitClient();
cc.doImport(new File(subVersionedDirectory), SVNURL.parseURIEncoded(repositoryURL), "<import> " + commitMessage, null, false, true, SVNDepth.fromRecurse(true));

我还发现一段代码可能会在提交之前将丢失的文件标记为DELETED

cc.setCommitParameters(new ISVNCommitParameters() {
   // delete even those files
   // that are not scheduled for deletion.
   public Action onMissingFile(File file) {
      return DELETE;
   }
   public Action onMissingDirectory(File file) {
      return DELETE;
   }

   // delete files from disk after committing deletion.
   public boolean onDirectoryDeletion(File directory) {
      return true;
   }
   public boolean onFileDeletion(File file) {
      return true;
   }
   });
   cc.doCommit(new File[]{new File(subVersionedDirectory)}, false, "<commit> " + commitMessage, null, null, false, true, SVNDepth.INFINITY);

1 个答案:

答案 0 :(得分:6)

我的程序如何知道要提交的内容?

我找到的解决方案是使用doStatus在提交之前将已删除和添加的文件信息设置到工作副本

cm = SVNClientManager.newInstance(new DefaultSVNOptions());
// Use do status to set deleted and added files information into SVN working copy management
cm.getStatusClient().doStatus(subVersionedDirectory, SVNRevision.HEAD, SVNDepth.INFINITY, false, false, false, false, new ISVNStatusHandler() {
            @Override
            public void handleStatus(SVNStatus status) throws SVNException {
                if (SVNStatusType.STATUS_UNVERSIONED.equals(status.getNodeStatus())) {
                    cm.getWCClient().doAdd(status.getFile(), true, false, false, SVNDepth.EMPTY, false, false);
                } else if (SVNStatusType.MISSING.equals(status.getNodeStatus())) {
                    cm.getWCClient().doDelete(status.getFile(), true, false, false);
                }
            }
        }, null);        
cm.getCommitClient().doCommit(new File[]{subVersionedDirectory}, false, "<commit> " + commitMessage, null, null, false, true, SVNDepth.INFINITY);