List of usage examples for org.eclipse.jgit.api PushCommand call
@Override public Iterable<PushResult> call() throws GitAPIException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
Execute the push command with all the options and parameters collected by the setter methods of this class.
From source file:org.apache.zeppelin.notebook.repo.GitHubNotebookRepo.java
License:Apache License
private void pushToRemoteSteam() { try {/*from w ww.jav a 2 s . c o m*/ LOG.debug("Pushing latest changes to remote stream"); PushCommand pushCommand = git.push(); pushCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken())); pushCommand.call(); } catch (GitAPIException e) { LOG.error("Error when pushing latest changes to remote repository", e); } }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Push to Remote//from www. j a va 2 s .c o m * @param localGitFolder * @param userName * @param userPassword * @return * @throws IOException * @throws GitAPIException */ public static Iterable<PushResult> pushToRemote(File localGitFolder, String userName, String userPassword, ProgressMonitor monitor) throws IOException, GitAPIException { try (Git git = Git.open(localGitFolder)) { PushCommand pushCommand = git.push(); pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword)); pushCommand.setProgressMonitor(monitor); return pushCommand.call(); } }
From source file:org.codehaus.mojo.versions.BumpMojo.java
License:Apache License
void gitPush(String o, String d) throws MojoExecutionException { try {/*from w w w .ja v a2 s. c o m*/ RefSpec spec = new RefSpec(d + ":" + d); PushCommand ff = git.push(); ff.setRemote(o); ff.setRefSpecs(spec); ff.setPushTags(); Iterable<PushResult> f = ff.call(); } catch (GitAPIException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.eclipse.orion.server.filesystem.git.GitFileStore.java
License:Open Source License
private void push() throws CoreException { try {/*from w w w. ja v a 2 s . c om*/ Repository local = getLocalRepo(); Git git = new Git(local); PushCommand push = git.push(); push.setRefSpecs(new RefSpec("refs/heads/*:refs/heads/*")); push.setCredentialsProvider(getCredentialsProvider()); Iterable<PushResult> pushResults = push.call(); for (PushResult pushResult : pushResults) { Collection<RemoteRefUpdate> updates = pushResult.getRemoteUpdates(); for (RemoteRefUpdate update : updates) { org.eclipse.jgit.transport.RemoteRefUpdate.Status status = update.getStatus(); if (status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK) || status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.UP_TO_DATE)) { LogHelper.log(new Status(IStatus.INFO, Activator.PI_GIT, 1, "Push succeed: " + this, null)); } else { throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT, IStatus.ERROR, status.toString(), null)); } } } } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT, IStatus.ERROR, e.getMessage(), e)); } }
From source file:org.eclipse.orion.server.git.jobs.PushJob.java
License:Open Source License
private IStatus doPush() throws IOException, CoreException, URISyntaxException, GitAPIException { // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Git git = new Git(db); PushCommand pushCommand = git.push(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote); credentials.setUri(remoteConfig.getURIs().get(0)); pushCommand.setCredentialsProvider(credentials); RefSpec spec = new RefSpec(srcRef + ':' + Constants.R_HEADS + branch); pushCommand.setRemote(remote).setRefSpecs(spec); if (tags)//from w ww . ja v a 2 s. c o m pushCommand.setPushTags(); pushCommand.setForce(force); Iterable<PushResult> resultIterable = pushCommand.call(); PushResult pushResult = resultIterable.iterator().next(); // this set will contain only OK status or UP_TO_DATE status Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>(); for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) { final String rm = rru.getRemoteName(); // check status only for branch given in the URL or tags if (branch.equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) { RemoteRefUpdate.Status status = rru.getStatus(); // any status different from UP_TO_DATE and OK should generate warning if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE) return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name(), new Throwable(rru.getMessage())); // add OK or UP_TO_DATE status to the set statusSet.add(status); } // TODO: return results for all updated branches once push is available for remote, see bug 352202 } if (statusSet.contains(RemoteRefUpdate.Status.OK)) // if there is OK status in the set -> something was updated return Status.OK_STATUS; else // if there is no OK status in the set -> only UP_TO_DATE status is possible return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name()); }
From source file:org.eclipse.orion.server.git.servlets.PushJob.java
License:Open Source License
private IStatus doPush() throws IOException, CoreException, JGitInternalException, InvalidRemoteException, URISyntaxException, JSONException { // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Git git = new Git(db); PushCommand pushCommand = git.push(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), path.segment(0)); credentials.setUri(remoteConfig.getURIs().get(0)); pushCommand.setCredentialsProvider(credentials); // ObjectId ref = db.resolve(srcRef); RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$ pushCommand.setRemote(path.segment(0)).setRefSpecs(spec); if (tags)/* www .j a va 2 s . c o m*/ pushCommand.setPushTags(); pushCommand.setForce(force); Iterable<PushResult> resultIterable = pushCommand.call(); PushResult pushResult = resultIterable.iterator().next(); // this set will contain only OK status or UP_TO_DATE status Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>(); for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) { final String rm = rru.getRemoteName(); // final String sr = rru.isDelete() ? null : rru.getSrcRef(); // check status only for branch given in the URL or tags if (path.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) { RemoteRefUpdate.Status status = rru.getStatus(); // any status different from UP_TO_DATE and OK should generate warning if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE) return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name()); // add OK or UP_TO_DATE status to the set statusSet.add(status); } // TODO: return results for all updated branches once push is available for remote, see bug 342727, comment 1 } if (statusSet.contains(RemoteRefUpdate.Status.OK)) // if there is OK status in the set -> something was updated return Status.OK_STATUS; else // if there is no OK status in the set -> only UP_TO_DATE status is possible return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name()); }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
public boolean pushToUpstreamInternal(ServiceInvocationContext context, Repository repository, RemoteConfig pushConfig, String remote) { ProgressMonitor monitor = ProgressMonitor.create( GitPlugin.getInstance().getMessage("git.push.monitor.title"), context.getCommunicationChannel()); try {/* www .jav a 2 s . c o m*/ if (repository == null) { context.getCommunicationChannel().appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), "Cannot find repository " + repository, DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } GitProgressMonitor gitMonitor = new GitProgressMonitor(monitor); PushCommand command; if (remote != null) { command = new Git(repository).push().setRemote(remote); } else { List<RefSpec> specs = new ArrayList<RefSpec>(); for (String refMapping : pushConfig.getPushMappings()) { specs.add(new RefSpec(refMapping)); } command = new Git(repository).push().setRemote(new URIish(pushConfig.getUri()).toPrivateString()) .setRefSpecs(specs); } command.setProgressMonitor(gitMonitor); command.setCredentialsProvider(new GitUsernamePasswordCredentialsProvider()); Iterable<PushResult> resultIterable = command.call(); PushResult pushResult = resultIterable.iterator().next(); context.getCommunicationChannel() .appendOrSendCommand(new DisplaySimpleMessageClientCommand( GitPlugin.getInstance().getMessage("git.push.result"), GitPlugin.getInstance().getUtils().handlePushResult(pushResult), DisplaySimpleMessageClientCommand.ICON_INFORMATION)); return true; } catch (Exception e) { if (GitPlugin.getInstance().getUtils().isAuthentificationException(e)) { openLoginWindow(); return true; } logger.debug(GitPlugin.getInstance().getMessage("git.push.error"), e); context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } finally { monitor.done(); } }
From source file:org.jabylon.team.git.GitTeamProvider.java
License:Open Source License
@Override public void commit(ProjectVersion project, IProgressMonitor monitor) throws TeamProviderException { try {/*www .j a v a2s . c o m*/ Repository repository = createRepository(project); SubMonitor subMon = SubMonitor.convert(monitor, "Commit", 100); Git git = new Git(repository); // AddCommand addCommand = git.add(); List<String> changedFiles = addNewFiles(git, subMon.newChild(30)); if (!changedFiles.isEmpty()) { checkCanceled(subMon); CommitCommand commit = git.commit(); Preferences node = PreferencesUtil.scopeFor(project.getParent()); String username = node.get(GitConstants.KEY_USERNAME, "Jabylon"); String email = node.get(GitConstants.KEY_EMAIL, "jabylon@example.org"); String message = node.get(GitConstants.KEY_MESSAGE, "Auto Sync-up by Jabylon"); boolean insertChangeId = node.getBoolean(GitConstants.KEY_INSERT_CHANGE_ID, false); commit.setAuthor(username, email); commit.setCommitter(username, email); commit.setInsertChangeId(insertChangeId); commit.setMessage(message); for (String path : changedFiles) { checkCanceled(subMon); commit.setOnly(path); } commit.call(); subMon.worked(10); } else { LOGGER.info("No changed files, skipping commit phase"); } checkCanceled(subMon); PushCommand push = git.push(); URI uri = project.getParent().getRepositoryURI(); if (uri != null) push.setRemote(stripUserInfo(uri).toString()); push.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(60))); if (!"https".equals(uri.scheme()) && !"http".equals(uri.scheme())) push.setTransportConfigCallback(createTransportConfigCallback(project.getParent())); push.setCredentialsProvider(createCredentialsProvider(project.getParent())); RefSpec spec = createRefSpec(project); push.setRefSpecs(spec); Iterable<PushResult> result = push.call(); for (PushResult r : result) { for (RemoteRefUpdate rru : r.getRemoteUpdates()) { if (rru.getStatus() != RemoteRefUpdate.Status.OK && rru.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE) { String error = "Push failed: " + rru.getStatus(); LOGGER.error(error); throw new TeamProviderException(error); } } } Ref ref = repository.getRef(project.getName()); if (ref != null) { LOGGER.info("Successfully pushed {} to {}", ref.getObjectId(), project.getParent().getRepositoryURI()); } } catch (NoHeadException e) { throw new TeamProviderException(e); } catch (NoMessageException e) { throw new TeamProviderException(e); } catch (ConcurrentRefUpdateException e) { throw new TeamProviderException(e); } catch (JGitInternalException e) { throw new TeamProviderException(e); } catch (WrongRepositoryStateException e) { throw new TeamProviderException(e); } catch (InvalidRemoteException e) { throw new TeamProviderException(e); } catch (IOException e) { throw new TeamProviderException(e); } catch (GitAPIException e) { throw new TeamProviderException(e); } finally { if (monitor != null) monitor.done(); } }
From source file:org.jboss.arquillian.ce.template.GitAdapter.java
License:Open Source License
public GitAdapter push(String remote) throws Exception { PushCommand push = git.push(); push.setRemote(remote);/*www .j a va2 s. c o m*/ push.setCredentialsProvider(credentials); push.call(); return this; }
From source file:org.jboss.arquillian.container.openshift.express.util.GitUtil.java
License:Apache License
/** * Pushes local repository upstream//from www .j a va2s .c om * * @param credentialsProvider the credentials provider to get SSH pass phrase */ public void push(CredentialsProvider credentialsProvider) { PushCommand push = git.push(); push.setCredentialsProvider(credentialsProvider); try { push.call(); } catch (JGitInternalException e) { throw new IllegalStateException("Unable to push into remote Git repository", e); } catch (InvalidRemoteException e) { throw new IllegalStateException("Unable to push into remote Git repository", e); } }