1

How to commit a particular file instead of a whole directory in SVN using SVNKit?

Code to commit whole dir:

        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager((String) session.getAttribute("USERNAME"), (String) session.getAttribute("PASSWORD"));
        repository.setAuthenticationManager(authManager);

        SVNClientManager ourClientManager = SVNClientManager.newInstance(null,repository.getAuthenticationManager());
        SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
        updateClient.doUpdate(wcDir, SVNRevision.HEAD, SVNDepth.INFINITY, false, false);
        ourClientManager.getWCClient().doInfo(wcDir, SVNRevision.HEAD);
        SVNCommitInfo s1=ourClientManager.getCommitClient().doCommit(new File[] {wcDir}, true, "From Code", svnProperties.getRegularProperties(), null, true, false, SVNDepth.INFINITY);
1
  • 1
    Please post the code you are currently using to commit a whole directory. Commented Mar 20, 2013 at 10:06

1 Answer 1

7

If you use SVNKit as a library, use this code:

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
    final SvnCommit commit = svnOperationFactory.createCommit();
    commit.setSingleTarget(SvnTarget.fromFile(file));
    commit.setCommitMessage("Commit message");
    final SVNCommitInfo commitInfo = commit.run();
} finally {
    svnOperationFactory.dispose();
}

If you use SVNKit as command line instrument, run:

$ jsvn commit path/to/file

Update: Here's the code for 1.3.x

final SVNClientManager clientManager = SVNClientManager.newInstance();
try {
    final SVNCommitClient commitClient = clientManager.getCommitClient();
    final SVNCommitInfo commitInfo = commitClient.doCommit(new File[]{file}, false, "Commit message", null, null, false, false, SVNDepth.INFINITY);
} finally {
    clientManager.dispose();
}
Sign up to request clarification or add additional context in comments.

4 Comments

I am using svnkit 1.3.5 jar file. when used above code,it shows me error.
This code is for SVNKit 1.7.x. For 1.3.x use SVNClientManager to create SVNCommitClient and call SVNCommitClient#doCommit of the file you want to commit.
I have pasted my code for committing the whole directory. but i couldn't commit a specific file.
What happens if you replace wcDir with file to commit?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.