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

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

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

Git.cloneRepository介绍

[英]Return a command object to execute a clone command
[中]返回命令对象以执行克隆命令

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

public CloneCommand getCloneCommandByCloneRepository() {
    CloneCommand command = Git.cloneRepository();
    return command;
  }
}

代码示例来源:origin: oracle/helidon

CloneCommand cloneCommand = Git.cloneRepository()
    .setURI(uri.toASCIIString())
    .setBranchesToClone(singleton("refs/heads/" + branch))

代码示例来源:origin: apache/incubator-gobblin

fileKey.open(false).create(true);
this.gitForPush = Git.cloneRepository().setURI(GIT_REMOTE_REPO_DIR).setDirectory(new File(GIT_CLONE_DIR)).call();

代码示例来源:origin: apache/incubator-gobblin

this.git = Git.cloneRepository()
  .setDirectory(repoDirFile)
  .setURI(this.repoUri)

代码示例来源:origin: apache/incubator-gobblin

this.remoteRepo.create(true);
this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();

代码示例来源:origin: apache/incubator-gobblin

remoteRepo.create(true);
Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();

代码示例来源:origin: apache/incubator-gobblin

@BeforeClass
public void setup() throws Exception {
 cleanUpDir(TEST_DIR);
 // Create a bare repository
 RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED);
 this.remoteRepo = fileKey.open(false);
 this.remoteRepo.create(true);
 this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();
 // push an empty commit as a base for detecting changes
 this.gitForPush.commit().setMessage("First commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
 this.config = ConfigBuilder.create()
   .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI,
     this.remoteRepo.getDirectory().getAbsolutePath())
   .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig")
   .addPrimitive(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog")
   .addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
   .build();
 this.flowCatalog = new FlowCatalog(config);
 this.flowCatalog.startAsync().awaitRunning();
 this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog);
 this.gitConfigMonitor.setActive(true);
}

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

private static Repository cloneRepository() throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      return result.getRepository();
    }
  }
}

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

private static Repository cloneRepository() throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      return result.getRepository();
    }
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      System.out.println("Having repository: " + result.getRepository().getDirectory());
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      System.out.println("Having repository: " + result.getRepository().getDirectory());
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

代码示例来源:origin: FlowCI/flow-platform

/**
 * Clone code to folder
 *
 * @param gitUrl
 * @param targetDir
 * @return
 * @throws GitException
 */
public static Path clone(String gitUrl, Path targetDir) throws GitException {
  CloneCommand cloneCommand = Git.cloneRepository()
    .setURI(gitUrl)
    .setDirectory(targetDir.toFile());
  try (Git ignored = cloneCommand.call()) {
    return targetDir;
  } catch (GitAPIException e) {
    throw new GitException("Fail to clone git repo", e);
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      System.out.println("Having repository: " + result.getRepository().getDirectory());
      try (Git git = new Git(result.getRepository())) {
        git.pull()
        .call();
      }

      System.out.println("Pulled from remote repository to local repository at " + result.getRepository().getDirectory());
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new folder for the cloned repository
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
      throw new IOException("Could not delete temporary file " + localPath);
    }

    // then clone
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    try (Git result = Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .call()) {
      // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
      System.out.println("Having repository: " + result.getRepository().getDirectory());
      try (Git git = new Git(result.getRepository())) {
        git.pull()
        .call();
      }

      System.out.println("Pulled from remote repository to local repository at " + result.getRepository().getDirectory());
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

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

try (Git git = Git.cloneRepository()
    .setURI(REMOTE_URL)
    .setDirectory(localPath)

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

try (Git result = Git.cloneRepository()
    .setURI(REMOTE_URL)
    .setDirectory(localPath)

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

try (Git result = Git.cloneRepository()
    .setURI(REMOTE_URL)
    .setDirectory(localPath)

代码示例来源:origin: FlowCI/flow-platform

@Override
public File clone(String branch, boolean noCheckout) throws GitException {
  checkGitUrl();
  CloneCommand cloneCommand = Git.cloneRepository()
    .setURI(gitUrl)
    .setNoCheckout(noCheckout)
    .setBranch(branch)
    .setDirectory(targetDir.toFile());
  try (Git git = buildCommand(cloneCommand).call()) {
    return git.getRepository().getDirectory();
  } catch (GitAPIException e) {
    throw new GitException("Fail to clone git repo", e);
  }
}

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

callback.cloningSubmodule(generator.getPath());
CloneCommand clone = Git.cloneRepository();
configure(clone);
clone.setURI(url);

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

@Override
  public RemoteFile readFileWithMode(String uri, String ref, String path)
      throws GitAPIException, IOException {
    File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
    try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
        .setURI(uri).call()) {
      Repository repo = git.getRepository();
      ObjectId refCommitId = sha1(uri, ref);
      if (refCommitId == null) {
        throw new InvalidRefNameException(MessageFormat
            .format(JGitText.get().refNotResolved, ref));
      }
      RevCommit commit = repo.parseCommit(refCommitId);
      TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree());
      // TODO(ifrade): Cope better with big files (e.g. using
      // InputStream instead of byte[])
      return new RemoteFile(
          tw.getObjectReader().open(tw.getObjectId(0))
              .getCachedBytes(Integer.MAX_VALUE),
          tw.getFileMode(0));
    } finally {
      FileUtils.delete(dir, FileUtils.RECURSIVE);
    }
  }
}

相关文章