Checking Out Directory / File with SVNKit

14,453

Solution 1

You cannot check out a file in Subversion. You have to check out a folder.

To check out a folder with one or more files:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
updateClient.doCheckout(url, destPath, revision, revision,
            isRecursive);

To commit a previously checked out folder:

SVNClientManager ourClientManager = SVNClientManager.newInstance(null, 
            repository.getAuthenticationManager());
ourClientManager.getWCClient().doInfo(wcPath, SVNRevision.HEAD);
ourClientManager.getCommitClient().doCommit
        (new File[] { wcPath }, keepLocks, commitMessage, false, true);

Solution 2

As SVNKit developer, I would recommend you to prefer new API based on SvnOperationFactory. The old API (based on SVNClientManager) will be operational still but all new SVN features will come only to the new API.

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
    final SvnCheckout checkout = svnOperationFactory.createCheckout();
    checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
    checkout.setSource(SvnTarget.fromURL(url));
    //... other options
    checkout.run();
} finally {
    svnOperationFactory.dispose();
}
Share:
14,453
Federer
Author by

Federer

Updated on July 02, 2022

Comments

  • Federer
    Federer almost 2 years

    I can't see on the wiki where checking out is documented. Ideally, I would like to check out a file "example/folder/file.xml", if not just the folder... and then when the application closes down or otherwise, be able to commit back in changes to this file. How do I do this?

  • My Head Hurts
    My Head Hurts almost 12 years
    +1 very useful answer. In addition, if you want to export a file then you can do this using updateClient.doExport(url, destPath, revision, revision, eolStyle, force, isRecursive)
  • user3274901
    user3274901 over 11 years
    The listed overload of doExport is deprecated in SVNKit 1.7.5-v1. Instead I used the following overload: updateClient.doCheckout(url, destPath, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true);
  • Lucy
    Lucy over 9 years
    On using the above code I'm getting a warning "The method doCheckout(SVNURL, File, SVNRevision, SVNRevision, boolean) from the type SVNUpdateClient is deprecated"...Any idea which method to use instead of doCheckout??
  • Lucy
    Lucy over 9 years
    so we have to declare workingCopyDirectory as "File workingCopyDirectory=new File("/home/lucy");" ???
  • Lucy
    Lucy over 9 years
    ok..I have another doubt..Will SvnOperationFactory copy a folder also along with files stored at a particukar SVN path or just the files??
  • Dmitry Pavlenko
    Dmitry Pavlenko over 9 years
    It will behave in the same manner as svn co <url> <workingCopyDirectory> does: workingCopyDirectory will contain the same files and directories as url does.
  • Lucy
    Lucy over 9 years
    I have used the above code twice to checkout 2 directories from svn. Is there a better way of doing it??
  • Dmitry Pavlenko
    Dmitry Pavlenko over 9 years
    No, there's no way to checkout several working copies in one operation.
  • Lucy
    Lucy over 9 years
    So what i have done here stackoverflow.com/questions/27099430/… is correct??
  • Dmitry Pavlenko
    Dmitry Pavlenko over 9 years
    Yes, this is the best way to do that.
  • Lucy
    Lucy over 9 years
    Ok Thanks a Lot for the clarification!!
  • Varun Sharma
    Varun Sharma about 7 years
    @DmitryPavlenko I'm trying to checkout from a repository (dump | load) in my machine and the URL is :- SVNURL secondUrl = SVNURL.fromFile(new File("/home/vsharma/svn/API_Work/hotcopy/test")); but i'm getting exceptions:- org.tmatesoft.svn.core.SVNException: svn: E180001: Unable to open an ra_local session to URL svn: E180001: Unable to open repository 'file:///home/vsharma/svn/API_Work/hotcopy/test' svn: E125006: '/home/vsharma/svn/API_Work/hotcopy/test/db/format' contains invalid filesystem format option 'addressing logical' Any way to make it work?
  • Dmitry Pavlenko
    Dmitry Pavlenko about 7 years
    'addressing logical' feature was added in later SVNKit versions (>=1.8.12), so retry with the latest version. Also I would like to note that "checkout" operation has nothing to do with "svnadmin dump/load". For "svnadmin" commands look at SVNAdminClient class.
  • Varun Sharma
    Varun Sharma about 7 years
    @DmitryPavlenko Anything over 1.8.7 is crashing JRE even in debugger.
  • Dmitry Pavlenko
    Dmitry Pavlenko about 7 years
    That is probably related to Gnome Keyring: stackoverflow.com/questions/39342816/… I've fixed the issue in SVNKit repository but we didn't publish a release yet. For now you can either turn Gnome Keyring off, or wait for the next release (it will be soon), or build SVNKit from sources.
  • Jean-François Côté
    Jean-François Côté over 6 years
    I have the same problem, it take forever to finish... There must a parameter missing. Did you ever get it solved?