4

I develop a Java program using the SVNKit library that will be responsible to update or commit a directory under version control. The directory content can be changed by another program which I don't have control, this program can add, delete or edit files ignoring to set subversion information.

Question is «How can my program know what to commit» ?

Because new files were not added I tried to process a doImport of rootDirectory but it causes an SVNException saying that file already exist at repository side.

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

I also find a piece of code that will probably mark missing files as DELETED before commit

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);
Valéry Stroeder
  • 613
  • 1
  • 6
  • 15

1 Answers1

7

How can my program know what to commit?

The solution I found is to use doStatus to set deleted and added files information to the working copy just before commit

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);
Valéry Stroeder
  • 613
  • 1
  • 6
  • 15
  • 1
    +1. However the if clause for deleted files should be checking against `STATUS_MISSING` (not `MISSING`). At least on the newest version of svnkit (1.8.7 at the time of writing) – K Erlandsson Apr 23 '15 at 14:14