List of usage examples for org.eclipse.jgit.api PushCommand setProgressMonitor
public PushCommand setProgressMonitor(ProgressMonitor monitor)
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {/* w ww .java2 s. c o m*/ StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.update(config); config.save(); } String currentBranch = git.getRepository().getBranch(); List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch)); if (deleteRemoteBranch != null) { specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch)); } PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false); if (getUri() != null) { pushCommand.setRemote(getUri()); } setupCredentials(pushCommand); if (includeTags) { pushCommand.setPushTags(); } if (getProgressMonitor() != null) { pushCommand.setProgressMonitor(getProgressMonitor()); } Iterable<PushResult> pushResults = pushCommand.setForce(true).call(); for (PushResult pushResult : pushResults) { log(pushResult.getMessages()); GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates()); GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates()); } } catch (Exception e) { if (pushFailedProperty != null) { getProject().setProperty(pushFailedProperty, e.getMessage()); } throw new GitBuildException(PUSH_FAILED_MESSAGE, e); } }
From source file:es.logongas.openshift.ant.impl.OpenShiftUtil.java
License:Apache License
public void gitPushApplication(String serverUrl, String userName, String password, String domainName, String applicationName, String privateKeyFile, String path) throws GitAPIException, IOException { SshSessionFactory.setInstance(new CustomConfigSessionFactory(privateKeyFile)); Git git = Git.open(new File(path)); PushCommand push = git.push(); push.setProgressMonitor(new TextProgressMonitor()); LOGGER.info("Finalizado push"); LOGGER.info("Mostrando resultados"); Iterable<PushResult> pushResults = push.call(); for (PushResult pushResult : pushResults) { LOGGER.info(pushResult.getMessages()); }// w w w . j a v a 2 s.c o m }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Push to Remote//from ww w . ja v a2s . 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.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 {/* w ww. j a va 2 s .c om*/ 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 {/* w w w . ja va2 s. co 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.zend.sdkcli.internal.commands.GitPushApplicationCommand.java
License:Open Source License
@Override protected boolean doExecute() { Repository repo = null;/* w w w . j a v a 2 s . c om*/ try { File gitDir = getRepo(); if (!gitDir.exists()) { getLogger().error("Git repository is not available in provided location"); return false; } repo = FileRepositoryBuilder.create(getRepo()); } catch (IOException e) { getLogger().error(e); return false; } if (repo != null) { Git git = new Git(repo); String remote = doGetRemote(repo); if (remote == null) { getLogger().error("Invalid remote value: " + getRemote()); return false; } // perform operation only if it is clone of phpCloud repository String repoUrl = git.getRepository().getConfig().getString("remote", remote, "url"); AddCommand addCommand = git.add(); addCommand.setUpdate(false); // add all new files addCommand.addFilepattern("."); try { addCommand.call(); } catch (NoFilepatternException e) { // should not occur because '.' is used getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } CommitCommand commitCommand = git.commit(); // automatically stage files that have been modified and deleted commitCommand.setAll(true); PersonIdent ident = getPersonalIdent(repoUrl); if (ident == null) { getLogger().error("Invalid author information provided: " + getAuthor()); return false; } commitCommand.setAuthor(ident); commitCommand.setInsertChangeId(true); commitCommand.setMessage(getMessage()); try { commitCommand.call(); } catch (Exception e) { getLogger().error(e); return false; } // at the end push all changes PushCommand pushCommand = git.push(); pushCommand.setPushAll(); pushCommand.setRemote(remote); pushCommand.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); try { URIish uri = new URIish(repoUrl); if (GITHUB_HOST.equals(uri.getHost()) && "git".equals(uri.getUser())) { if (!prepareSSHFactory()) { return false; } } else { CredentialsProvider credentials = getCredentials(repoUrl); if (credentials != null) { pushCommand.setCredentialsProvider(credentials); } } Iterable<PushResult> result = pushCommand.call(); for (PushResult pushResult : result) { pushResult.getAdvertisedRefs(); Collection<RemoteRefUpdate> updates = pushResult.getRemoteUpdates(); for (RemoteRefUpdate remoteRefUpdate : updates) { TrackingRefUpdate trackingRefUpdate = remoteRefUpdate.getTrackingRefUpdate(); getLogger().info(MessageFormat.format("Remote name: {0}, status: {1}", remoteRefUpdate.getRemoteName(), remoteRefUpdate.getStatus().toString())); getLogger().info(MessageFormat.format("Remote name: {0}, result: {1}", trackingRefUpdate.getRemoteName(), trackingRefUpdate.getResult().toString())); } } } catch (JGitInternalException e) { getLogger().error(e); return false; } catch (InvalidRemoteException e) { // should not occur because selected remote is available getLogger().error(e); return false; } catch (URISyntaxException e) { getLogger().error(e); return false; } catch (TransportException e) { getLogger().error(e); return false; } catch (GitAPIException e) { getLogger().error(e); return false; } } return true; }