org.eclipse.jgit.api.Git.submoduleAdd()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.eclipse.jgit.api.Git.submoduleAdd()方法的一些代码示例,展示了Git.submoduleAdd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.submoduleAdd()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:submoduleAdd

Git.submoduleAdd介绍

[英]Return a command object to execute a submodule add command
[中]返回命令对象以执行子模块添加命令

代码示例

代码示例来源:origin: centic9/jgit-cookbook

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");
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

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");
      }
    }
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

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();
  }
}

代码示例来源:origin: jenkinsci/git-client-plugin

/** {@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);
  }
}

代码示例来源:origin: com.atlassian.sdk/ap3-api

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);
  }
}

代码示例来源:origin: line/centraldogma

@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);
}

代码示例来源:origin: berlam/github-bucket

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();
  }
}

代码示例来源:origin: sonia.jgit/org.eclipse.jgit

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();
    }
  }
}

相关文章