add folders and commit files using SVNKit
Asked Answered
I

2

9

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));
}
Innocence answered 19/12, 2012 at 9:1 Comment(3)
So, you've imported a directory to Apache Subversion repository. It will not make the local directory a working copy, so the only option for you is to 'svn import' new files. Why don't you want to checkout a working copy? What's the task?Dragonnade
I am developing a application, in which user can create application. and i provided the option to check-in their project from my app itself. i used above code, which adds project to repository, but it is not making version control for the check-in folder.Innocence
you can call "checkout" on this directory after all, it won't overwrite existing files.Ricci
G
1

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.

Geraldine answered 15/3, 2013 at 19:38 Comment(0)
A
0

This is the way SVN works, if you want to commit future changes you need to make the local folder a working copy, and to get a working copy you need to do a check out.

An alternative I use sometimes is

  • create an empty folder directly in the repository,
  • checking out that folder on the local folder (making it a working copy with its .svn folder)
  • then adding and commiting existing files
Antiphony answered 7/1, 2013 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.