List of usage examples for org.eclipse.jgit.api PushCommand getRemote
public String getRemote()
From source file:com.surevine.gateway.scm.git.jgit.JGitGitFacade.java
License:Open Source License
@Override public void push(final LocalRepoBean repoBean, final String remoteName) throws GitException { try {/*from ww w . j a v a 2 s. com*/ FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(repoBean.getRepoDirectory().toFile()).findGitDir().build(); Git git = new org.eclipse.jgit.api.Git(repository); // dry run the push - if the push cannot be done automatically we have no way to recover so we just log // and throw an exception PushCommand dryRunPushCommand = git.push(); dryRunPushCommand.setRemote(remoteName); dryRunPushCommand.setDryRun(true); Iterable<PushResult> dryRunResult = dryRunPushCommand.call(); for (PushResult result : dryRunResult) { for (RemoteRefUpdate remoteRefUpdate : result.getRemoteUpdates()) { switch (remoteRefUpdate.getStatus()) { case OK: case UP_TO_DATE: continue; default: throw new GitException("During a dry run of a push one of the updates would have failed " + "so the push was aborted for repo " + repoBean + " to remote " + dryRunPushCommand.getRemote()); } } } // if we get to this point the dry run was OK so try the real thing PushCommand realPushCommand = git.push(); realPushCommand.setRemote(remoteName); Iterable<PushResult> pushResults = realPushCommand.call(); for (PushResult result : pushResults) { for (RemoteRefUpdate remoteRefUpdate : result.getRemoteUpdates()) { switch (remoteRefUpdate.getStatus()) { case OK: case UP_TO_DATE: continue; default: throw new GitException( "Push failed for " + repoBean + " to remote " + dryRunPushCommand.getRemote()); } } } } catch (GitAPIException | IOException e) { LOGGER.error(e); throw new GitException(e); } }