List of usage examples for org.eclipse.jgit.transport PushResult getMessages
public String getMessages()
From source file:com.amazonaws.eclipse.elasticbeanstalk.git.AWSGitPushCommand.java
License:Open Source License
public void execute() throws CoreException { Iterable<PushResult> pushResults = null; try {/*from w w w .j ava 2 s .c o m*/ Repository repository = initializeRepository(); // Add the new files clearOutRepository(repository); extractZipFile(archiveFile, repoLocation); commitChanges(repository, "Incremental Deployment: " + new Date().toString()); // Push to AWS String remoteUrl = getRemoteUrl(); if (log.isLoggable(Level.FINE)) log.fine("Pushing to: " + remoteUrl); PushCommand pushCommand = new Git(repository).push().setRemote(remoteUrl).setForce(true).add("master"); // TODO: we could use a ProgressMonitor here for reporting status back to the UI pushResults = pushCommand.call(); } catch (Throwable t) { throwCoreException(null, t); } for (PushResult pushResult : pushResults) { String messages = pushResult.getMessages(); if (messages != null && messages.trim().length() > 0) { throwCoreException(messages, null); } } }
From source file:com.google.gerrit.acceptance.git.ssh.PushForReviewIT.java
License:Apache License
private static void assertStatus(Status expectedStatus, String expectedMessage, PushResult result, String ref) { RemoteRefUpdate refUpdate = result.getRemoteUpdate(ref); assertEquals(refUpdate.getMessage() + "\n" + result.getMessages(), expectedStatus, refUpdate.getStatus()); assertEquals(expectedMessage, refUpdate.getMessage()); }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
License:Apache License
private void grantDatabaseAccess() throws RepositoryException { final String targetRevision = "refs/meta/config"; String filePath = gc.getWorkingDirectoryPath() + File.separator + "MetaConfig"; String projectConfig = filePath + File.separator + "project.config"; String url = String.format("ssh://%s@%s:%d/%s", gc.getUsername(), gc.getHost(), gc.getPort(), "All-Projects.git"); boolean accessDBFound = false; Scanner scanner = null;// ww w .java2s . c o m JGitRepository jgitRepo = new JGitRepository(); if (dbAccessGranted) return; synchronized (GerritService.class) { try { jgitRepo.setAccessData(gc); jgitRepo.open(filePath, true); jgitRepo.openSSHTransport(url); jgitRepo.fetch(targetRevision); jgitRepo.checkout(targetRevision); StringBuilder content = new StringBuilder(); File fConfig = new File(projectConfig); scanner = new Scanner(fConfig); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains("accessDatabase = group Administrators")) { accessDBFound = true; break; } content.append(line).append("\n"); if (line.contains("[capability]")) { content.append("\taccessDatabase = group Administrators\n"); } } scanner.close(); if (accessDBFound) { dbAccessGranted = true; return; } File fConfig2 = new File(projectConfig); FileUtils.writeStringToFile(fConfig2, content.toString()); jgitRepo.add("project.config"); PushResult r = jgitRepo.commitPush("Grant Database Access.", targetRevision); if (r.getMessages().contains("ERROR")) { throw new RepositoryException(r.getMessages()); } dbAccessGranted = true; } catch (org.eclipse.jgit.errors.TransportException e) { throw new RepositoryException(e); } catch (FileNotFoundException e) { throw new RepositoryException( "Could not locate the project.config! Your checkout must have failed."); } catch (IOException e) { throw new RepositoryException(e); } finally { jgitRepo.close(); if (scanner != null) scanner.close(); } } }
From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java
License:Apache License
private void installVerificationLabel() throws RepositoryException { final String targetRevision = "refs/meta/config"; String filePath = gc.getWorkingDirectoryPath() + File.separator + "MetaConfig"; String projectConfig = filePath + File.separator + "project.config"; String url = String.format("ssh://%s@%s:%d/%s", gc.getUsername(), gc.getHost(), gc.getPort(), "All-Projects.git"); boolean verifiedSectionFound = false; Scanner scanner = null;// w w w . ja v a2 s .c o m JGitRepository jgitRepo = new JGitRepository(); if (verifiedLabelAdded) return; synchronized (GerritService.class) { try { jgitRepo.setAccessData(gc); jgitRepo.open(filePath, true); jgitRepo.openSSHTransport(url); jgitRepo.fetch(targetRevision); jgitRepo.checkout(targetRevision); StringBuilder content = new StringBuilder(); File fConfig = new File(projectConfig); scanner = new Scanner(fConfig); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains("[label \"Verified\"]")) { verifiedSectionFound = true; break; } content.append(line).append("\n"); if (line.contains("[access \"refs/heads/*\"]")) { content.append("\tlabel-Verified = -1..+1 group Administrators\n"); } } scanner.close(); if (verifiedSectionFound) { verifiedLabelAdded = true; return; } content.append("[label \"Verified\"]\n"); content.append("\tfunction = MaxWithBlock\n"); content.append("\tvalue = -1 Fails\n"); content.append("\tvalue = 0 No score\n"); content.append("\tvalue = +1 Verified\n"); File fConfig2 = new File(projectConfig); FileUtils.writeStringToFile(fConfig2, content.toString()); jgitRepo.add("project.config"); PushResult r = jgitRepo.commitPush("Enabled verification label.", targetRevision); if (r.getMessages().contains("ERROR")) { throw new RepositoryException(r.getMessages()); } verifiedLabelAdded = true; } catch (org.eclipse.jgit.errors.TransportException e) { throw new RepositoryException(e); } catch (FileNotFoundException e) { throw new RepositoryException( "Could not locate the project.config! Your checkout must have failed."); } catch (IOException e) { throw new RepositoryException(e); } finally { jgitRepo.close(); if (scanner != null) scanner.close(); } } }
From source file:com.osbitools.ws.shared.prj.utils.GitUtils.java
License:Open Source License
/** * Push git changes to remote git repository * /* w ww . j a va 2 s . c o m*/ * @param git Local git repository * @param name Remote name * @param url Remote Git url * @return push result * @throws WsSrvException */ public static String pushToRemote(Git git, String name, String url) throws WsSrvException { checkRemoteGitConfig(name, url); try { String res = ""; Iterable<PushResult> pres = git.push().setRemote(name).call(); for (PushResult r : pres) res += r.getMessages(); return res; } catch (GitAPIException e) { throw new WsSrvException(249, e, "Error push to remote [" + name + "]"); } }
From source file:com.passgit.app.PassGit.java
License:Open Source License
public void pushRepository() { try (Git git = new Git(gitRepository)) { Iterable<PushResult> pushResults = git.push().call(); for (PushResult result : pushResults) { System.out.println(result.getMessages()); }/*from w ww . j a v a 2s. c om*/ } catch (GitAPIException ex) { Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {/*from w ww. j av a2 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:com.tenxdev.ovcs.command.AbstractOvcsCommand.java
License:Open Source License
/** * Push all committed changes to the remote repository * * @param git/*from w ww . j a va2s .co m*/ * the local git repository * @throws GitAPIException * if the push operation failed */ protected void doPush(final Git git) throws GitAPIException { final Iterable<PushResult> pushResults = git.push().setRemote("origin").add("master") .setProgressMonitor(new TextProgressMonitor()).call(); for (final PushResult pushResult : pushResults) { final String messages = pushResult.getMessages(); if (!"".equals(messages)) { System.out.println(); } } }
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();//from w w w . j a va2 s. c o m 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()); } }
From source file:ezbake.deployer.publishers.openShift.RhcApplication.java
License:Apache License
/** * Updates the OpenShift application with the changes locally applied. (git commit, git Push) * This will cause the new app to be deployed to openshift. After this the new version should be visible. * * @throws DeploymentException On any error deploying the application. *///from ww w. ja v a 2 s. c o m public void publishChanges() throws DeploymentException { try { RevCommit commit = gitRepo.commit().setMessage("RhcApplication: publishing newest version") .setAuthor(applicationDomain.getUser().getRhlogin(), applicationDomain.getUser().getRhlogin()) .call(); log.info("[" + getApplicationName() + "][GIT-COMMIT] committed changes to local git repo. " + commit.toString()); PushCommand pushCommand = gitRepo.push(); if (gitCredentialsProvider != null) pushCommand.setCredentialsProvider(gitCredentialsProvider); for (PushResult result : pushCommand.setForce(true).setTimeout(100000).call()) { if (!result.getMessages().isEmpty()) log.info("[" + getApplicationName() + "][GIT-PUSH] " + result.getMessages()); log.info("[" + getApplicationName() + "][GIT-PUSH] Successfully pushed application."); } } catch (GitAPIException e) { log.error("[" + getApplicationName() + "] Error adding updated files to deployment git repo", e); throw new DeploymentException(e.getMessage()); } }