Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add folders and commit files using SVNKit

Tags:

java

svn

svnkit

I've just created a Java project. I want to check-in this project to SVN location with help of SVNKit.

I use the below code, which adds a folder to SVN repository. But it didn't create any .svn folder in the folder /Users/test/svnAddDirCheck.

I want the files to be cheked-in and also I want to commit some changed files in future. Without checking out the source code, how can I do this ? Can I add these files in SVN as well as I can commit any changed files directly ?

@Test
public void importWholeDir() throws Exception {
    try {
        DAVRepositoryFactory.setup();
        SVNRepositoryFactoryImpl.setup();
        FSRepositoryFactory.setup();

        String svnUrl = "https://abc.com/svn/repos/projects/test/CREATE2";
        File dir = new File("/Users/test/svnAddDirCheck");
        SVNURL url = SVNURL.parseURIDecoded(svnUrl);
        String userName = "XXXXXXX";
        String userPassword = "XXXXXXXXX";

        importDirectoryContentToSubversion(svnUrl, dir.getPath(), userName, userPassword, "directory and file added");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static SVNCommitInfo importDirectoryContentToSubversion(final String repositoryURL, final String subVersionedDirectory, final String userName, final String hashedPassword, final String commitMessage) throws SVNException {
    final SVNClientManager cm = SVNClientManager.newInstance(new DefaultSVNOptions(), userName, hashedPassword);
    return cm.getCommitClient().doImport(new File(subVersionedDirectory), SVNURL.parseURIEncoded(repositoryURL), "<import> " + commitMessage, null, false, true, SVNDepth.fromRecurse(true));
}
like image 339
Muthu Avatar asked Dec 19 '12 09:12

Muthu


1 Answers

I assuming SVNKit is actually doing an svn add of the to the repository and not the working copy? Is that correct?

If so, you can't add files to a repository unless you have the folder that will contain the files checked out.

Also What version of SVN are you using? 1.7 no longer places a .svn folder in every folder of your working copy, only in the root folder.

Essentially what you want to do, psuedo code is:

  1. Check out the directory where you want to add folders/files. If it is a folder that contains other folder files you can check it out with a depth of --empty so you won't get any other files/folders that may be checked into that folder.

  2. Create your new folder/files.

  3. Use svn kit to "add" the files to the working copy.

  4. Use svn kit to "commit" the working copy which will add the folder/files to the repository.

Of course, step 1 only needs to be done if you haven't already done it. Your could should follow the same steps you would follow manually. I suggest you review the svn documentation on basic usage. Once you can do what you want to do with svn.exe it should be fairly easy to duplicate it using svnkit API.

like image 182
PilotBob Avatar answered Nov 14 '22 00:11

PilotBob