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

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

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

Git.pull介绍

[英]Return a command object to execute a Pull command
[中]返回命令对象以执行拉动命令

代码示例

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

private void pull() throws GitAPIException {
  Git git = recordGit(Git.wrap(repository));
  PullCommand pull = git.pull()
      .setRebase(true);
  PullResult result = pull.call();
  if (!result.isSuccessful()) {
    LOGGER.log(Level.WARNING, () -> String.format("Cannot pull from git '%s', branch '%s'", uri.toASCIIString(), branch));
    if (LOGGER.isLoggable(Level.FINEST)) {
      Status status = git.status().call();
      LOGGER.finest(() -> "git status cleanliness: " + status.isClean());
      if (!status.isClean()) {
        LOGGER.finest(() -> "git status uncommitted changes: " + status.getUncommittedChanges());
        LOGGER.finest(() -> "git status untracked: " + status.getUntracked());
      }
    }
  } else {
    LOGGER.fine("Pull was successful.");
  }
  LOGGER.finest(() -> "git rebase result: " + result.getRebaseResult().getStatus().name());
  LOGGER.finest(() -> "git fetch result: " + result.getFetchResult().getMessages());
}

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

private PullCommand pullCommand(String branch, Git git) {
  if (Strings.isNullOrEmpty(branch)) {
    return buildCommand(git.pull());
  }
  return buildCommand(git.pull().setRemoteBranchName(branch)).setTimeout(GIT_TRANS_TIMEOUT);
}

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

@Signature
public Memory pull(String remote, ArrayMemory settings) throws GitAPIException {
  PullCommand command = getWrappedObject().pull();

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

public static void main(String[] args) throws IOException, GitAPIException {
  final File localPath;
  try (Repository repository = cloneRepository()) {
    localPath = repository.getWorkTree();
    System.out.println("Having repository: " + repository.getDirectory() + " with head: " +
        repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" +
        repository.resolve("refs/heads/master"));
    // TODO: why do we get null here for HEAD?!? See also
// http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception
    try (Git git = new Git(repository)) {
      PullResult call = git.pull().call();
      System.out.println("Pulled from the remote repository: " + call);
    }
  }
  // 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 {
  final File localPath;
  try (Repository repository = cloneRepository()) {
    localPath = repository.getWorkTree();
    System.out.println("Having repository: " + repository.getDirectory() + " with head: " +
        repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" +
        repository.resolve("refs/heads/master"));
    // TODO: why do we get null here for HEAD?!? See also
// http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception
    try (Git git = new Git(repository)) {
      PullResult call = git.pull().call();
      System.out.println("Pulled from the remote repository: " + call);
    }
  }
  // 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

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: cfg4j/cfg4j

private void reload() {
 try {
  LOG.debug("Reloading configuration by pulling changes");
  clonedRepo.pull().call();
 } catch (GitAPIException e) {
  initialized = false;
  throw new IllegalStateException("Unable to pull from remote repository", e);
 }
}

代码示例来源:origin: com.societegenerale.ci-droid.tasks-consumer/ci-droid-tasks-consumer-infrastructure

public PullResult pull(Git git) throws GitAPIException {
  return git.pull().call();
}

代码示例来源:origin: stackoverflow.com

private void pullWithRebase(Git git) throws GitAPIException {
  git.checkout().setName("master").call();
  List<Ref> branches = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
  String remoteMasterBranchName = "refs/remotes/origin/master";
  for (Ref ref : branches) {
    if (remoteMasterBranchName.equals(ref.getName())) {
      git.pull().setRemoteBranchName("master").setRebase(true).call();
      return;
    }
  }
}

代码示例来源:origin: com.meltmedia.cadmium/cadmium-core

public boolean pull() throws Exception {
 log.debug("Pulling latest updates from remote git repo");
 return git.pull().call().isSuccessful();
}

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

/**
 * Pulls changes form the default remote repository into the wrapped repository.
 *
 * @throws GitAPIException - failed.
 */
public void pull() throws GitAPIException {
  if (!isUndefined()) {
    git.pull().call();
  }
}

代码示例来源:origin: io.fabric8.forge/fabric8-forge-core

protected void doPull(Git git, GitContext context) throws GitAPIException {
  StopWatch watch = new StopWatch();
  LOG.info("Performing a pull in git repository " + this.gitFolder + " on remote URL: " + this.remoteRepository);
  CredentialsProvider cp = userDetails.createCredentialsProvider();
  PullCommand command = git.pull();
  configureCommand(command, userDetails);
  command.setCredentialsProvider(cp).setRebase(true).call();
  LOG.info("Took " + watch.taken() + " to complete pull in git repository " + this.gitFolder + " on remote URL: " + this.remoteRepository);
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public PullResult pull(final Git git, final int timeout) throws GitAPIException
{
 PullCommand pull = git.pull();
 if (timeout >= 0)
   pull.setTimeout(timeout);
 pull.setProgressMonitor(new TextProgressMonitor());
 PullResult result = pull.call();
 return result;
}

代码示例来源:origin: com.centurylink.mdw/mdw-common

public void pull(String branch) throws Exception {
  PullCommand pull = git.pull().setRemote("origin").setRemoteBranchName(branch);
  if (credentialsProvider != null)
    pull.setCredentialsProvider(credentialsProvider);
  pull.call();
}

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

private Collection<String> attemptRebase() throws GitAPIException {
  val conflicts = new HashSet<String>();
  createStashIfNeeded();
  val pr = git.pull().setStrategy(MergeStrategy.RESOLVE).setRebase(true).call();
  if (pr.getRebaseResult().getConflicts() != null) {
    conflicts.addAll(pr.getRebaseResult().getConflicts());
  }
  conflicts.addAll(applyStashIfNeeded());
  return conflicts;
}

代码示例来源:origin: indeedeng/proctor

private Git pullRepository(final File workingDir) throws GitAPIException, IOException {
  final Git git = Git.open(workingDir);
  git.pull().setProgressMonitor(PROGRESS_MONITOR)
      .setRebase(true)
      .setCredentialsProvider(user)
      .setTimeout(pullPushTimeoutSeconds)
      .call();
  return git;
}

代码示例来源:origin: com.indeed/proctor-store-git

private Git pullRepository(final File workingDir) throws GitAPIException, IOException {
  final Git git = Git.open(workingDir);
  git.pull().setProgressMonitor(PROGRESS_MONITOR)
      .setRebase(true)
      .setCredentialsProvider(user)
      .setTimeout(pullPushTimeoutSeconds)
      .call();
  return git;
}

代码示例来源:origin: Calsign/APDE

public void pullRepo() {
  try {
    git.pull().setRemote(REMOTE_NAME).setRemoteBranchName(MASTER_BRANCH).setRebase(false).call();
  } catch (InvalidRemoteException e) {
    e.printStackTrace();
  } catch (TransportException e) {
    e.printStackTrace();
  } catch (GitAPIException e) {
    e.printStackTrace();
  }
}

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

public static void updateRepo(File directory) throws GitAPIException {
  if (getGit() != null) {
    getGit().pull().call();
  } else {
    Git.cloneRepository().setDirectory(directory).setURI("https://github.com/FlareBot/FlareBot.git").call();
  }
}

相关文章