List of usage examples for org.eclipse.jgit.api PullCommand setRemoteBranchName
public PullCommand setRemoteBranchName(String remoteBranchName)
From source file:org.jplus.jenkins.plugin.git.GITRepositoryUtils.java
@Override public void update() { try {/*from w w w .java2 s . c om*/ LOGGER.debug("update git:" + repositoryPath); CheckoutCommand checkout = git.checkout(); ObjectId resolve = repo.resolve("master"); if (resolve == null) { checkout.setCreateBranch(true); } checkout.setForce(true); checkout.setStage(CheckoutCommand.Stage.THEIRS); checkout.setName("master"); checkout.call(); ResetCommand reset = git.reset(); reset.setMode(ResetCommand.ResetType.HARD); reset.setRef("HEAD"); reset.call(); PullCommand pull = git.pull(); pull.setRebase(true); pull.setRemote("origin"); pull.setRemoteBranchName("master"); pull.setStrategy(MergeStrategy.THEIRS); pull.call(); } catch (Exception ex) { Logger.getLogger(GITRepositoryUtils.class.getName()).log(Level.SEVERE, "update git:" + repositoryPath + " error!!!", ex); } }
From source file:us.rader.dinodocs.GitPuller.java
License:Apache License
/** * Pull the latest sources for the "master" branch from the "origin" remote * of a local Git repository.//from w w w .j a v a 2 s.c o m * * @param localRepository * File system path to local repository * * @param branch * Branch name * * @throws Exception * Thrown if the Git pull operation fails. */ private void pullRepository(File localRepository, String branch) throws Exception { try (Git git = Git.open(localRepository)) { PullCommand pullCommand = git.pull(); pullCommand.setRemote(REMOTE_NAME); pullCommand.setRemoteBranchName(branch); PullResult pullResult = pullCommand.call(); if (!pullResult.isSuccessful()) { throw new Exception( MessageFormat.format("Failed to pull into {0}", localRepository.getCanonicalPath())); //$NON-NLS-1$ } CheckoutCommand checkoutCommand = git.checkout(); checkoutCommand.setName(branch); checkoutCommand.call(); CheckoutResult checkoutResult = checkoutCommand.getResult(); if (!checkoutResult.getStatus().equals(CheckoutResult.Status.OK)) { throw new Exception(MessageFormat.format("Failed to check out {0}", branch)); //$NON-NLS-1$ } if (logger.isLoggable(Level.FINE)) { logger.logp(Level.FINE, getClass().getName(), "pullRepository)", MessageFormat //$NON-NLS-1$ .format("successfully pulled {0}/{1}", localRepository.getCanonicalPath(), branch)); //$NON-NLS-1$ } } }