简体   繁体   中英

add folders and commit files using 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));
}

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM