public static ArrayMemory valueOf(PushResult value) { ArrayMemory memory = valueOf((OperationResult) value); memory.refOfIndex("remoteUpdates").assign(valueOfRemoteRefUpdates(value.getRemoteUpdates())); return memory; }
private boolean allCommitsArePushedWithSuccess(Iterable<PushResult> forcePushResult) { long nbCommitsWithNotOkStatus = StreamSupport.stream(forcePushResult.spliterator(), false) .flatMap(pushResult -> pushResult.getRemoteUpdates().stream()) .filter(result -> result.getStatus() != RemoteRefUpdate.Status.OK) .count(); return (nbCommitsWithNotOkStatus == 0); }
/** * Method description * * * @param git * @param result * * @return */ private long count(Git git, PushResult result) { long counter = 0; Collection<RemoteRefUpdate> updates = result.getRemoteUpdates(); for (RemoteRefUpdate update : updates) { counter += count(git, update); } return counter; }
private void logPushResultDetails(Iterable<PushResult> forcePushResult) { if (log.isInfoEnabled()) { StringBuilder sb = new StringBuilder("force push results : \n"); for (PushResult pushResult : forcePushResult) { Collection<RemoteRefUpdate> pushResultDetails = pushResult.getRemoteUpdates(); for (RemoteRefUpdate result : pushResultDetails) { sb.append("- ").append(result.getRemoteName()) .append(" - ").append(result.getStatus().name()) .append(" - ").append(result.getNewObjectId()); } } log.info(sb.toString()); } }
/** * Inspect the push returns to know if the push command has succeeded. * * @param call The push results object. * @return Returns <code>true</code> pushed, <code>false</code> otherwise. */ private static boolean isPushed(Iterable<PushResult> call) { for (PushResult pr : call) { Optional<RemoteRefUpdate> any = pr.getRemoteUpdates().stream() .filter(ru -> !(RemoteRefUpdate.Status.OK.equals(ru.getStatus()) || RemoteRefUpdate.Status.UP_TO_DATE.equals(ru.getStatus()))).findAny(); if (any.isPresent()) { return false; } } return true; }
public void logPushResult(Iterable<PushResult> results, Repository repository, boolean verbose) throws IOException { String local = repository.getDirectory().getCanonicalPath(); for (PushResult result : results) { Map<String, RemoteRefUpdate> map = new TreeMap<>(); for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (verbose || update.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE) { map.put(update.getSrcRef(), update); } } if (map.size() > 0) { LOG.info(String.format("Pushed from %s to %s:", local, result.getURI())); for (RemoteRefUpdate update : map.values()) { LOG.info(String.format(" - %s (%s)", update.getSrcRef(), update.getStatus())); } } else { LOG.info(String.format("Pushed from %s to %s - no reference was updated", local, result.getURI())); } } }
@Override public void logPushResult(Iterable<PushResult> results, Repository repository, boolean verbose) throws IOException { String local = repository.getDirectory().getCanonicalPath(); for (PushResult result : results) { Map<String, RemoteRefUpdate> map = new TreeMap<>(); for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (verbose || update.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE) { map.put(update.getSrcRef(), update); } } if (map.size() > 0) { Activator.log(LogService.LOG_INFO, String.format("Pushed from %s to %s:", local, result.getURI())); for (RemoteRefUpdate update : map.values()) { Activator.log(LogService.LOG_INFO, String.format(" - %s (%s)", update.getSrcRef(), update.getStatus())); } } else { Activator.log(LogService.LOG_INFO, String.format("Pushed from %s to %s - no reference was updated", local, result.getURI())); } } }
@Override public void logPushResult(Iterable<PushResult> results, Repository repository, boolean verbose) throws IOException { String local = repository.getDirectory().getCanonicalPath(); for (PushResult result : results) { Map<String, RemoteRefUpdate> map = new TreeMap<>(); for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (verbose || update.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE) { map.put(update.getSrcRef(), update); } } if (map.size() > 0) { Activator.log(LogService.LOG_INFO, String.format("Pushed from %s to %s:", local, result.getURI())); for (RemoteRefUpdate update : map.values()) { Activator.log(LogService.LOG_INFO, String.format(" - %s (%s)", update.getSrcRef(), update.getStatus())); } } else { Activator.log(LogService.LOG_INFO, String.format("Pushed from %s to %s - no reference was updated", local, result.getURI())); } } }
protected RevCommit commitThenPush(Git git, String branch, CommitCommand commit) throws Exception { RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (isPushOnCommit()) { Iterable<PushResult> results = doPush(git); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates())); } } } return answer; }
protected RevCommit commitThenPush(Git git, CommitCommand commit) throws Exception { RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (isPushOnCommit()) { Iterable<PushResult> results = doPush(git); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates())); } } } return answer; }
private void printPushResult(final ObjectReader reader, final URIish uri, final PushResult result) throws IOException { shownURI = false; boolean everythingUpToDate = true; // at first, print up-to-date ones... for (final RemoteRefUpdate rru : result.getRemoteUpdates()) { if (rru.getStatus() == Status.UP_TO_DATE) { if (verbose) printRefUpdateResult(reader, uri, result, rru); } else everythingUpToDate = false; } for (final RemoteRefUpdate rru : result.getRemoteUpdates()) { // ...then successful updates... if (rru.getStatus() == Status.OK) printRefUpdateResult(reader, uri, result, rru); } for (final RemoteRefUpdate rru : result.getRemoteUpdates()) { // ...finally, others (problematic) if (rru.getStatus() != Status.OK && rru.getStatus() != Status.UP_TO_DATE) printRefUpdateResult(reader, uri, result, rru); } AbstractFetchCommand.showRemoteMessages(errw, result.getMessages()); if (everythingUpToDate) outw.println(CLIText.get().everythingUpToDate); }
@Override public String publish(String name) throws ConfigurationPersistenceException { StringBuilder message = new StringBuilder(); String remoteName = gitRepository.getRemoteName(name); if (remoteName != null && gitRepository.isValidRemoteName(remoteName)) { try (Git git = gitRepository.getGit()) { Iterable<PushResult> result = git.push().setRemote(remoteName) .setRefSpecs(new RefSpec(gitRepository.getBranch() + ':' + gitRepository.getBranch())) .setPushTags().call(); for (PushResult pushResult : result) { for (RemoteRefUpdate refUpdate : pushResult.getRemoteUpdates()) { message.append(refUpdate.getMessage()).append(" ").append(refUpdate.getNewObjectId().name()).append('\n'); } } } catch (GitAPIException ex) { throw MGMT_OP_LOGGER.failedToPublishConfiguration(ex, name, ex.getMessage()); } } return message.toString(); }
@Override public String publish(String name) throws ConfigurationPersistenceException { StringBuilder message = new StringBuilder(); String remoteName = gitRepository.getRemoteName(name); if (remoteName != null && gitRepository.isValidRemoteName(remoteName)) { try (Git git = gitRepository.getGit()) { Iterable<PushResult> result = git.push().setRemote(remoteName) .setRefSpecs(new RefSpec(gitRepository.getBranch() + ':' + gitRepository.getBranch())) .setPushTags().call(); for (PushResult pushResult : result) { for (RemoteRefUpdate refUpdate : pushResult.getRemoteUpdates()) { message.append(refUpdate.getMessage()).append(" ").append(refUpdate.getNewObjectId().name()).append('\n'); } } } catch (GitAPIException ex) { throw MGMT_OP_LOGGER.failedToPublishConfiguration(ex, name, ex.getMessage()); } } return message.toString(); }
public static RevCommit doCommitAndPush(Git git, String message, UserDetails userDetails, PersonIdent author, String branch, String origin, boolean pushOnCommit) throws GitAPIException { CommitCommand commit = git.commit().setAll(true).setMessage(message); if (author != null) { commit = commit.setAuthor(author); } RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (pushOnCommit) { PushCommand push = git.push(); configureCommand(push, userDetails); Iterable<PushResult> results = push.setRemote(origin).call(); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates())); } } } return answer; }
protected RevCommit doCommitAndPush(Git git, String message, CredentialsProvider credentials, PersonIdent author, String remote, String branch) throws IOException, GitAPIException { CommitCommand commit = git.commit().setAll(true).setMessage(message); if (author != null) { commit = commit.setAuthor(author); } RevCommit answer = commit.call(); if (LOG.isDebugEnabled()) { LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage()); } if (isPushOnCommit()) { Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRemote(remote).call(); for (PushResult result : results) { if (LOG.isDebugEnabled()) { LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + GitHelpers.toString(result.getRemoteUpdates())); } } } return answer; }
public synchronized void backup() throws Exception { repo.add().setUpdate(false).addFilepattern(".").call(); Status status = repo.status().setIgnoreSubmodules(SubmoduleWalk.IgnoreSubmoduleMode.ALL).call(); log.debug("status.getUncommittedChanges() = " + status.getUncommittedChanges()); if (!status.getUncommittedChanges().isEmpty()) { for (String missingPath : status.getMissing()) { repo.rm().addFilepattern(missingPath).call(); } log.info("Changes detected in the following files: " + status.getUncommittedChanges()); repo.commit() .setMessage("Backing up data dir") .setAuthor("AppRunner BackupService", "noemail@example.org") .call(); Iterable<PushResult> pushResults = repo.push().call(); for (PushResult pushResult : pushResults) { log.info("Result of pushing to remote: " + pushResult.getRemoteUpdates()); } } else { log.info("No changes to back up"); } }
void setData(final Repository localDb, final PushOperationResult result) { reader = localDb.newObjectReader(); repo = localDb; // Set empty result for a while. treeViewer.setInput(null); if (result == null) { root.layout(); return; } final List<RefUpdateElement> results = new ArrayList<RefUpdateElement>(); for (URIish uri : result.getURIs()) if (result.isSuccessfulConnection(uri)) for (RemoteRefUpdate update : result.getPushResult(uri) .getRemoteUpdates()) results.add(new RefUpdateElement(result, update, uri, reader, repo)); treeViewer.setInput(results.toArray()); // select the first row of table to get the details of the first // push result shown in the Text control Tree table = treeViewer.getTree(); if (table.getItemCount() > 0) treeViewer.setSelection(new StructuredSelection(table.getItem(0) .getData())); root.layout(); }
public static Iterable<PushResult> push( ScmLogger logger, Git git, GitScmProviderRepository repo, RefSpec refSpec ) throws GitAPIException, InvalidRemoteException, TransportException { CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo ); Iterable<PushResult> pushResultList = git.push().setCredentialsProvider( credentials ).setRefSpecs( refSpec ).call(); for ( PushResult pushResult : pushResultList ) { Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates(); for ( RemoteRefUpdate remoteRefUpdate : ru ) { logger.info( remoteRefUpdate.getStatus() + " - " + remoteRefUpdate.toString() ); } } return pushResultList; }
public static Iterable<PushResult> push( ScmLogger logger, Git git, GitScmProviderRepository repo, RefSpec refSpec ) throws GitAPIException, InvalidRemoteException, TransportException { CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo ); PushCommand command = git.push().setRefSpecs(refSpec).setCredentialsProvider(credentials) .setTransportConfigCallback(new JGitTransportConfigCallback(repo, logger)); Iterable<PushResult> pushResultList = command.call(); for ( PushResult pushResult : pushResultList ) { Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates(); for ( RemoteRefUpdate remoteRefUpdate : ru ) { logger.info( remoteRefUpdate.getStatus() + " - " + remoteRefUpdate.toString() ); } } return pushResultList; }
@Override public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { RefSpec ref = (refspec != null) ? new RefSpec(fixRefSpec(repo)) : Transport.REFSPEC_PUSH_ALL; listener.getLogger().println("RefSpec is \""+ref+"\"."); Git g = git(repo); Config config = g.getRepository().getConfig(); config.setString("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url", remote.toPrivateASCIIString()); org.eclipse.jgit.api.PushCommand pc = g.push().setRemote("org_jenkinsci_plugins_gitclient_JGitAPIImpl").setRefSpecs(ref) .setProgressMonitor(new JGitProgressMonitor(listener)) .setCredentialsProvider(getProvider()) .setForce(force); if(tags) { pc.setPushTags(); } Iterable<PushResult> results = pc.call(); for(PushResult result:results) for(RemoteRefUpdate update:result.getRemoteUpdates()) { RemoteRefUpdate.Status status = update.getStatus(); if(!OK.equals(status)&&!UP_TO_DATE.equals(status)) { throw new GitException(update.getMessage() + " " + status + " for '" + ref + "' refspec '" + refspec + "' to " + remote.toPrivateASCIIString()); } } config.unset("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url"); } catch (IOException | JGitInternalException | GitAPIException e) { throw new GitException(e); } }