private static void addSubmodule(Repository mainRepo) throws GitAPIException { System.out.println("Adding submodule"); try (Git git = new Git(mainRepo)) { try (Repository subRepoInit = git.submoduleAdd(). setURI("https://github.com/github/testrepo.git"). setPath("testrepo"). call()) { if(subRepoInit.isBare()) { throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare"); } } } }
private static void addSubmodule(Repository mainRepo) throws GitAPIException { System.out.println("Adding submodule"); try (Git git = new Git(mainRepo)) { try (Repository subRepoInit = git.submoduleAdd(). setURI("https://github.com/github/testrepo.git"). setPath("testrepo"). call()) { if(subRepoInit.isBare()) { throw new IllegalStateException("Repository at " + subRepoInit.getDirectory() + " should not be bare"); } } } }
private void addSubmodule(String name, String url, String path, String revision, List<CopyFile> copyfiles, List<LinkFile> linkfiles, Git git) throws GitAPIException, IOException { assert (!repo.isBare()); assert (git != null); if (!linkfiles.isEmpty()) { throw new UnsupportedOperationException( JGitText.get().nonBareLinkFilesNotSupported); } SubmoduleAddCommand add = git.submoduleAdd().setName(name).setPath(path) .setURI(url); if (monitor != null) add.setProgressMonitor(monitor); Repository subRepo = add.call(); if (revision != null) { try (Git sub = new Git(subRepo)) { sub.checkout().setName(findRef(revision, subRepo)).call(); } subRepo.close(); git.add().addFilepattern(path).call(); } for (CopyFile copyfile : copyfiles) { copyfile.copy(); git.add().addFilepattern(copyfile.dest).call(); } }
/** {@inheritDoc} */ @Override public void addSubmodule(String remoteURL, String subdir) throws GitException { try (Repository repo = getRepository()) { git(repo).submoduleAdd().setPath(subdir).setURI(remoteURL).call(); } catch (GitAPIException e) { throw new GitException(e); } }
public static void addSubmoduleRecursively(Repository baseRepo, String submodule,String url, ProgressMonitor monitor) throws GitAPIException, IOException { Git git = new Git(baseRepo); Map<String,SubmoduleStatus> statuses = git.submoduleStatus().addPath(submodule).call(); Repository subRepo; if(statuses.isEmpty()) { subRepo = git.submoduleAdd().setPath(submodule).setURI(url).setProgressMonitor(monitor).call(); cloneSubmodule(subRepo,monitor); } else { subRepo = SubmoduleWalk.getSubmoduleRepository(git.getRepository(),submodule); updateSubmodule(subRepo,monitor); } }
@Test public void remoteToLocal_submodule() throws Exception { pushMirrorSettings(null, null); // Create a new repository for a submodule. final File gitSubmoduleWorkTree = new File(gitRepoDir.getRoot(), testName.getMethodName() + ".submodule").getAbsoluteFile(); final Repository gitSubmoduleRepo = new FileRepositoryBuilder().setWorkTree(gitSubmoduleWorkTree).build(); gitSubmoduleRepo.create(); final Git gitSubmodule = Git.wrap(gitSubmoduleRepo); final String gitSubmoduleUri = "file://" + (gitSubmoduleWorkTree.getPath().startsWith(File.separator) ? "" : "/") + gitSubmoduleWorkTree.getPath().replace(File.separatorChar, '/') + "/.git"; // Prepare the master branch of the submodule repository. addToGitIndex(gitSubmodule, gitSubmoduleWorkTree, "in_submodule.txt", "This is a file in a submodule."); gitSubmodule.commit().setMessage("Initial commit").call(); // Add the submodule. git.submoduleInit().call(); git.submoduleAdd().setPath("submodule").setURI(gitSubmoduleUri).call(); git.commit().setMessage("Add a new submodule").call(); // Check the files under a submodule do not match nor trigger an 'unknown object' error. mirroringService.mirror().join(); final Revision headRev = client.normalizeRevision(projName, REPO_FOO, Revision.HEAD).join(); final Entry<JsonNode> expectedMirrorState = expectedMirrorState(headRev, "/"); assertThat(client.getFiles(projName, REPO_FOO, Revision.HEAD, "/**").join().values()) .containsExactly(expectedMirrorState); }
private void addSubmodule(String name, String url, String path, String revision, List<CopyFile> copyfiles, List<LinkFile> linkfiles, Git git) throws GitAPIException, IOException { assert (!repo.isBare()); assert (git != null); if (!linkfiles.isEmpty()) { throw new UnsupportedOperationException( JGitText.get().nonBareLinkFilesNotSupported); } SubmoduleAddCommand add = git.submoduleAdd().setName(name).setPath(path) .setURI(url); if (monitor != null) add.setProgressMonitor(monitor); Repository subRepo = add.call(); if (revision != null) { try (Git sub = new Git(subRepo)) { sub.checkout().setName(findRef(revision, subRepo)).call(); } subRepo.close(); git.add().addFilepattern(path).call(); } for (CopyFile copyfile : copyfiles) { copyfile.copy(); git.add().addFilepattern(copyfile.dest).call(); } }
private void addSubmodule(String url, String name, String revision, List<CopyFile> copyfiles, Set<String> groups, String recommendShallow) throws GitAPIException, IOException { if (repo.isBare()) { RepoProject proj = new RepoProject(url, name, revision, null, groups, recommendShallow); proj.addCopyFiles(copyfiles); bareProjects.add(proj); } else { SubmoduleAddCommand add = git .submoduleAdd() .setPath(name) .setURI(url); if (monitor != null) add.setProgressMonitor(monitor); Repository subRepo = add.call(); if (revision != null) { try (Git sub = new Git(subRepo)) { sub.checkout().setName(findRef(revision, subRepo)) .call(); } subRepo.close(); git.add().addFilepattern(name).call(); } for (CopyFile copyfile : copyfiles) { copyfile.copy(); git.add().addFilepattern(copyfile.dest).call(); } } }