javasvnkit

How to add/commit a new file to SVN with SVNKit


Unable to add and commit a file to a subversion repository. With the following code snippet:

SVNCommitClient svnCommitClient = svnClientManager.getCommitClient();
svnCommitClient.doCommit(new File[]{new File("project/README.txt")}, false, "Commit message", null, null, false, false, SVNDepth.INFINITY); 

I get the following exception:

Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: E200009: Commit failed (details follow):
svn: E200009: 'D:\Java\POC\SvnKit\project\README.txt' is not under version control

Prompt what I did wrong, and I would like to see an example of how to


Solution

  • Welcome to Stackoverflow,

    like the exception already tells you, the file you want to be committed is not under version control yet, so you have to add it first.

    On your CommitEditor you should call something like this:

       SVNRepository repository = SVNRepositoryFactory.create( SVNURL.parseURIDecoded( url ) );
    
       ISVNEditor editor = repository.getCommitEditor( logMessage , null /*locks*/ , true /*keepLocks*/ , null /*mediator*/ );
    
       //the second and the third parameters are the path and revision respectively 
       //of the item's ancestor if the item is being added with history
       editor.addFile( "your/path/project/README.txt" , null , -1 );
    

    You should also have a look at the full example at SVNKit