@@ -0,0 +1,3313 @@
+package org.dstadler.jgit.unfinished;%0A%0A/*%0A   Copyright 2013, 2014 Dominik Stadler%0A%0A   Licensed under the Apache License, Version 2.0 (the %22License%22);%0A   you may not use this file except in compliance with the License.%0A   You may obtain a copy of the License at%0A%0A     http://www.apache.org/licenses/LICENSE-2.0%0A%0A   Unless required by applicable law or agreed to in writing, software%0A   distributed under the License is distributed on an %22AS IS%22 BASIS,%0A   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A   See the License for the specific language governing permissions and%0A   limitations under the License.%0A */%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport org.eclipse.jgit.api.Git;%0Aimport org.eclipse.jgit.api.errors.GitAPIException;%0Aimport org.eclipse.jgit.lib.Repository;%0Aimport org.eclipse.jgit.storage.file.FileRepositoryBuilder;%0A%0A%0A%0A/**%0A * Simple snippet which shows how to initialize a new repository%0A * %0A * @author dominik.stadler at gmx.at%0A */%0Apublic class TestSubmodules %7B%0A%0A    public static void main(String%5B%5D args) throws IOException, GitAPIException %7B%0A        File mainRepoDir = createRepository();%0A        %0A        Repository mainRepo = openMainRepo(mainRepoDir);%0A        %0A        addSubmodule(mainRepo);%0A        %0A        FileRepositoryBuilder builder = new FileRepositoryBuilder();%0A%0A        Repository subRepo = builder.setGitDir(new File(%22testrepo/.git%22))%0A          .readEnvironment() // scan environment GIT_* variables%0A          .findGitDir() // scan up the file system tree%0A          .build();%0A%0A        if(subRepo.isBare()) %7B%0A            throw new IllegalStateException(%22Repository at %22 + subRepo.getDirectory() + %22 should not be bare%22);%0A        %7D%0A%0A        System.out.println(%22All done!%22);%0A    %7D%0A%0A    private static void addSubmodule(Repository mainRepo) throws GitAPIException %7B%0A        System.out.println(%22Adding submodule%22);%0A        Repository subRepoInit = new Git(mainRepo).submoduleAdd().%0A                setURI(%22https://github.com/github/testrepo.git%22).%0A                setPath(%22testrepo%22).%0A                call();%0A        if(subRepoInit.isBare()) %7B%0A            throw new IllegalStateException(%22Repository at %22 + subRepoInit.getDirectory() + %22 should not be bare%22);%0A        %7D%0A    %7D%0A%0A    private static Repository openMainRepo(File mainRepoDir) throws IOException %7B%0A        FileRepositoryBuilder builder = new FileRepositoryBuilder();%0A%0A        Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), %22.git%22))%0A          .readEnvironment() // scan environment GIT_* variables%0A          .findGitDir() // scan up the file system tree%0A          .build();%0A%0A        if(mainRepo.isBare()) %7B%0A            throw new IllegalStateException(%22Repository at %22 + mainRepoDir + %22 should not be bare%22);%0A        %7D%0A        return mainRepo;%0A    %7D%0A%0A    private static File createRepository() throws IOException, GitAPIException %7B%0A        File dir = File.createTempFile(%22gitinit%22, %22.test%22);%0A        dir.delete();%0A%0A        Git.init()%0A                .setDirectory(dir)%0A                .call();%0A%0A        Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), %22.git%22));%0A%0A        System.out.println(%22Created a new repository at %22 + repository.getDirectory());%0A%0A        repository.close();%0A        %0A        return dir;%0A    %7D%0A%7D%0A

Add test for submodules