微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – SVNKit – 获取提交修改

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

问题是“我的程序如何知道要做什么”?

因为没有添加文件,所以我尝试处理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);

解决方法:

我的程序如何知道要提交什么?

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

cm = SVNClientManager.newInstance(new DefaultSVnoptions());
// Use do status to set deleted and added files @R_576_4045@ion 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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐