4

バージョン管理下のディレクトリの更新またはコミットを担当するSVNKitライブラリを使用してJavaプログラムを開発します。ディレクトリの内容は、私が制御できない別のプログラムによって変更される可能性があります。このプログラムは、サブバージョン情報の設定を無視してファイルを追加、削除、または編集できます。

質問は「私のプログラムはどのようにして何をコミットするかを知ることができますか」です。

新しいファイルが追加されなかったため、rootDirectoryのdoImportを処理しようとしましたが、ファイルがリポジトリ側にすでに存在することを示すSVNExceptionが発生します。

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

また、コミットする前に、欠落しているファイルを削除済みとしてマークする可能性のあるコードを見つけました

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);
4

1 に答える 1

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);
于 2012-09-11T11:02:33.890 に答える