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

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

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

Git.checkout介绍

[英]Return a command object to execute a checkout command
[中]返回命令对象以执行签出命令

代码示例

代码示例来源:origin: gocd/gocd

private void checkout(String branchName) throws GitAPIException {
  try {
    git.checkout().setName(branchName).call();
  } catch (GitAPIException e) {
    LOGGER.error("[CONFIG_MERGE] Checkout to branch {} failed", branchName, e);
    throw e;
  }
}

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

private Ref checkout(Git git, String label) throws GitAPIException {
  CheckoutCommand checkout = git.checkout();
  if (shouldTrack(git, label)) {
    trackBranch(git, checkout, label);
  }
  else {
    // works for tags and local branches
    checkout.setName(label);
  }
  return checkout.call();
}

代码示例来源:origin: gocd/gocd

private String getLatestConfigAt(String branchName) throws GitAPIException, IOException {
  configRepo.git().checkout().setName(branchName).call();
  String content = configRepo.getCurrentRevision().getContent();
  configRepo.git().checkout().setName("master").call();
  return content;
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSwitchToMasterAndDeleteTempBranches() throws Exception, GitAPIException {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_HEAD, configRepo.getCurrentRevCommit());
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  assertThat(configRepo.git().branchList().call().size(), is(3));
  configRepo.cleanAndResetToMaster();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCleanAndResetToMasterDuringInitialization() throws Exception {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  new ConfigRepository(systemEnvironment).initialize();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

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

public static Path checkout(Path path, String branch) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    git
      .checkout()
      .setName(branch)
      .call();
  } catch (Throwable throwable) {
    throw new GitException("fetch tags error", throwable);
  }
  return path;
}

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

public static void main(String[] args) throws IOException, GitAPIException {
  try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) {
    try (final Git git = new Git(repo)) {
      final String testFile = "README.md";
      // Modify the file
      FileUtils.write(new File(testFile), new Date().toString(), "UTF-8");
      System.out.println("Modified files: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, true).call();
      System.out.println("Modified files after assume-changed: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, false).call();
      System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git));
      git.checkout().addPath(testFile).call();
      System.out.println("Modified files after reset: " + getModifiedFiles(git));
    }
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
  try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) {
    try (final Git git = new Git(repo)) {
      final String testFile = "README.md";
      // Modify the file
      FileUtils.write(new File(testFile), new Date().toString(), "UTF-8");
      System.out.println("Modified files: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, true).call();
      System.out.println("Modified files after assume-changed: " + getModifiedFiles(git));
      new AssumeChangedCommand(repo, testFile, false).call();
      System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git));
      git.checkout().addPath(testFile).call();
      System.out.println("Modified files after reset: " + getModifiedFiles(git));
    }
  }
}

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

git.checkout().addPath(fileName).call();

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

git.checkout().addPath(fileName).call();

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory checkout(Environment env, ArrayMemory settings) throws GitAPIException {
  CheckoutCommand command = getWrappedObject().checkout();

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

Ref checkout = git.checkout().setName("changes").call();
System.out.println("Result of checking out the branch: " + checkout);
checkout = git.checkout().setName("master").call();
System.out.println("Result of checking out master: " + checkout);

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

Ref checkout = git.checkout().setName("changes").call();
System.out.println("Result of checking out the branch: " + checkout);
checkout = git.checkout().setName("master").call();
System.out.println("Result of checking out master: " + checkout);

代码示例来源: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: stackoverflow.com

String url = "https://github.com/renaud/solr_noLenghNormSimilarity";
String hash = "802558f58add3a1f5b33f04254194bd7cd59b27f";
String subPath = "src/org";
String dest = "myclone";

File localPath = new File(dest);

Git gitRepo = Git.cloneRepository().setURI(url).setDirectory(localPath).setNoCheckout(true).call();
gitRepo.checkout().setStartPoint(hash).addPath(subPath).call();
gitRepo.getRepository().close();

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Checks out the passed ref to be the current branch of the repository.
 *
 * @param ref - String representing a commit in the repository.
 * @throws GitAPIException - failed.
 */
public void checkout(final String ref) throws GitAPIException {
  git.checkout()
    .setName(ref)
    .call();
}

代码示例来源:origin: maks/MGit

private boolean checkout() {
  try {
    mRepo.getGit().checkout().addPath(mPath).call();
  } catch (StopTaskException e) {
    return false;
  } catch (Throwable e) {
    setException(e);
    return false;
  }
  return true;
}

代码示例来源:origin: sheimi/SGit

public void checkoutFromLocal(String name, String branch) throws GitAPIException,
  JGitInternalException, StopTaskException {
  mRepo.getGit().checkout().setCreateBranch(true).setName(branch)
      .setStartPoint(name).call();
}

代码示例来源:origin: maks/MGit

public void checkoutFromLocal(String name, String branch) throws GitAPIException,
  JGitInternalException, StopTaskException {
  mRepo.getGit().checkout().setCreateBranch(true).setName(branch)
      .setStartPoint(name).call();
}

代码示例来源:origin: sheimi/SGit

public void checkoutFromRemote(String remoteBranchName, String branchName)
      throws GitAPIException, JGitInternalException, StopTaskException {
    mRepo.getGit().checkout().setCreateBranch(true).setName(branchName)
        .setStartPoint(remoteBranchName).call();
    mRepo.getGit()
        .branchCreate()
        .setUpstreamMode(
            CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
        .setStartPoint(remoteBranchName).setName(branchName)
        .setForce(true).call();
  }
}

相关文章