List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate getRemoteName
public String getRemoteName()
From source file:com.google.gerrit.server.git.PushOp.java
License:Apache License
private void runImpl() throws IOException { final Transport tn = Transport.open(db, uri); final PushResult res; try {/*from ww w . jav a 2 s .c o m*/ res = pushVia(tn); } finally { try { tn.close(); } catch (Throwable e2) { log.warn("Unexpected error while closing " + uri, e2); } } for (final RemoteRefUpdate u : res.getRemoteUpdates()) { switch (u.getStatus()) { case OK: case UP_TO_DATE: case NON_EXISTING: break; case NOT_ATTEMPTED: case AWAITING_REPORT: case REJECTED_NODELETE: case REJECTED_NONFASTFORWARD: case REJECTED_REMOTE_CHANGED: log.error("Failed replicate of " + u.getRemoteName() + " to " + uri + ": status " + u.getStatus().name()); break; case REJECTED_OTHER_REASON: if ("non-fast-forward".equals(u.getMessage())) { log.error("Failed replicate of " + u.getRemoteName() + " to " + uri + ", remote rejected non-fast-forward push." + " Check receive.denyNonFastForwards variable in config file" + " of destination repository."); } else { log.error("Failed replicate of " + u.getRemoteName() + " to " + uri + ", reason: " + u.getMessage()); } break; } } }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private void updateStates(Collection<RemoteRefUpdate> refUpdates) throws LockFailureException { Set<String> doneRefs = new HashSet<>(); boolean anyRefFailed = false; RemoteRefUpdate.Status lastRefStatusError = RemoteRefUpdate.Status.OK; for (RemoteRefUpdate u : refUpdates) { RefPushResult pushStatus = RefPushResult.SUCCEEDED; Set<ReplicationState> logStates = new HashSet<>(); logStates.addAll(stateMap.get(u.getSrcRef())); logStates.addAll(stateMap.get(ALL_REFS)); ReplicationState[] logStatesArray = logStates.toArray(new ReplicationState[logStates.size()]); doneRefs.add(u.getSrcRef());//from w w w . ja v a2 s .c o m switch (u.getStatus()) { case OK: case UP_TO_DATE: case NON_EXISTING: break; case NOT_ATTEMPTED: case AWAITING_REPORT: case REJECTED_NODELETE: case REJECTED_NONFASTFORWARD: case REJECTED_REMOTE_CHANGED: stateLog.error(String.format("Failed replicate of %s to %s: status %s", u.getRemoteName(), uri, u.getStatus()), logStatesArray); pushStatus = RefPushResult.FAILED; anyRefFailed = true; lastRefStatusError = u.getStatus(); break; case REJECTED_OTHER_REASON: if ("non-fast-forward".equals(u.getMessage())) { stateLog.error( String.format( "Failed replicate of %s to %s" + ", remote rejected non-fast-forward push." + " Check receive.denyNonFastForwards variable in config file" + " of destination repository.", u.getRemoteName(), uri), logStatesArray); } else if ("failed to lock".equals(u.getMessage())) { throw new LockFailureException(uri, u.getMessage()); } else { stateLog.error(String.format("Failed replicate of %s to %s, reason: %s", u.getRemoteName(), uri, u.getMessage()), logStatesArray); } pushStatus = RefPushResult.FAILED; anyRefFailed = true; lastRefStatusError = u.getStatus(); break; } for (ReplicationState rs : getStatesByRef(u.getSrcRef())) { rs.notifyRefReplicated(projectName.get(), u.getSrcRef(), uri, pushStatus, u.getStatus()); } } doneRefs.add(ALL_REFS); for (ReplicationState rs : getStatesByRef(ALL_REFS)) { rs.notifyRefReplicated(projectName.get(), ALL_REFS, uri, anyRefFailed ? RefPushResult.FAILED : RefPushResult.SUCCEEDED, lastRefStatusError); } for (Map.Entry<String, ReplicationState> entry : stateMap.entries()) { if (!doneRefs.contains(entry.getKey())) { entry.getValue().notifyRefReplicated(projectName.get(), entry.getKey(), uri, RefPushResult.NOT_ATTEMPTED, null); } } stateMap.clear(); }
From source file:edu.wustl.lookingglass.community.CommunityRepository.java
License:Open Source License
private void push() throws GitAPIException, IOException, CommunityRepositoryException { assert this.credentials != null; assert this.remoteName != null; Iterable<PushResult> results = this.git.push().setCredentialsProvider(this.credentials) .setRemote(this.remoteName).call(); for (PushResult result : results) { for (final RemoteRefUpdate rru : result.getRemoteUpdates()) { // Find the push that matches our current branch to make sure it made it to the server. if (this.git.getRepository().getFullBranch().equals(rru.getRemoteName())) { if ((rru.getStatus() == RemoteRefUpdate.Status.OK) || (rru.getStatus() == RemoteRefUpdate.Status.UP_TO_DATE)) { // everything went well... } else { throw new CommunityRepositoryException("push failed: " + rru.getStatus()); }//from w w w. jav a2s. co m } } } }
From source file:io.fabric8.collector.git.GitHelpers.java
License:Apache License
public static String toString(Collection<RemoteRefUpdate> updates) { StringBuilder builder = new StringBuilder(); for (RemoteRefUpdate update : updates) { if (builder.length() > 0) { builder.append(" "); }/* w w w .j av a 2s. c om*/ builder.append(update.getMessage() + " " + update.getRemoteName() + " " + update.getNewObjectId()); } return builder.toString(); }
From source file:io.fabric8.forge.rest.git.RepositoryResource.java
License:Apache License
protected String toString(Collection<RemoteRefUpdate> updates) { StringBuilder builder = new StringBuilder(); for (RemoteRefUpdate update : updates) { if (builder.length() > 0) { builder.append(" "); }/*from ww w . jav a2 s . c o m*/ builder.append(update.getMessage() + " " + update.getRemoteName() + " " + update.getNewObjectId()); } return builder.toString(); }
From source file:io.fabric8.git.internal.DefaultPullPushPolicy.java
License:Apache License
@Override public synchronized PushPolicyResult doPush(GitContext context, CredentialsProvider credentialsProvider) { StoredConfig config = git.getRepository().getConfig(); String remoteUrl = config.getString("remote", remoteRef, "url"); if (remoteUrl == null) { LOGGER.debug("No remote repository defined, so not doing a push"); return new AbstractPushPolicyResult(); }//from w w w . j av a 2s . com LOGGER.info("Pushing last change to: {}", remoteUrl); Iterator<PushResult> resit = null; Exception lastException = null; try { resit = git.push().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider).setPushAll() .call().iterator(); } catch (GitAPIException | JGitInternalException ex) { lastException = ex; } // Allow the commit to stay in the repository in case of push failure if (lastException != null) { LOGGER.warn("Cannot push because of: {}", lastException.toString()); return new AbstractPushPolicyResult(lastException); } List<PushResult> pushResults = new ArrayList<>(); List<RemoteRefUpdate> acceptedUpdates = new ArrayList<>(); List<RemoteRefUpdate> rejectedUpdates = new ArrayList<>(); // Collect the updates that are not ok while (resit.hasNext()) { PushResult pushResult = resit.next(); pushResults.add(pushResult); for (RemoteRefUpdate refUpdate : pushResult.getRemoteUpdates()) { Status status = refUpdate.getStatus(); if (status == Status.OK || status == Status.UP_TO_DATE) { acceptedUpdates.add(refUpdate); } else { rejectedUpdates.add(refUpdate); } } } // Reset to the last known good rev and make the commit/push fail for (RemoteRefUpdate rejectedRef : rejectedUpdates) { LOGGER.warn("Rejected push: {}" + rejectedRef); String refName = rejectedRef.getRemoteName(); String branch = refName.substring(refName.lastIndexOf('/') + 1); try { GitHelpers.checkoutBranch(git, branch); FetchResult fetchResult = git.fetch().setTimeout(gitTimeout) .setCredentialsProvider(credentialsProvider).setRemote(remoteRef) .setRefSpecs(new RefSpec("refs/heads/" + branch)).call(); Ref fetchRef = fetchResult.getAdvertisedRef("refs/heads/" + branch); git.branchRename().setOldName(branch).setNewName(branch + "-tmp").call(); git.checkout().setCreateBranch(true).setName(branch).setStartPoint(fetchRef.getObjectId().getName()) .call(); git.branchDelete().setBranchNames(branch + "-tmp").setForce(true).call(); } catch (GitAPIException ex) { LOGGER.warn("Cannot reset branch {}, because of: {}", branch, ex.toString()); } } PushPolicyResult result = new AbstractPushPolicyResult(pushResults, acceptedUpdates, rejectedUpdates, lastException); LOGGER.info("Push result: {}", result); return result; }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
private PushResponse addCommandOutputUpdates(PushResponse pushResponseDto, final PushRequest request, final PushResult result) throws GitException { String commandOutput = result.getMessages(); final Collection<RemoteRefUpdate> refUpdates = result.getRemoteUpdates(); final List<Map<String, String>> updates = new ArrayList<>(); final String currentBranch = getCurrentBranch(); for (RemoteRefUpdate remoteRefUpdate : refUpdates) { final String remoteRefName = remoteRefUpdate.getRemoteName(); // check status only for branch given in the URL or tags - (handle special "refs/for" case) String shortenRefFor = remoteRefName.startsWith("refs/for/") ? remoteRefName.substring("refs/for/".length()) : remoteRefName;/*from ww w . j a v a2 s. com*/ if (currentBranch.equals(Repository.shortenRefName(remoteRefName)) || currentBranch.equals(shortenRefFor) || remoteRefName.startsWith(Constants.R_TAGS)) { Map<String, String> update = new HashMap<>(); RemoteRefUpdate.Status status = remoteRefUpdate.getStatus(); if (status != RemoteRefUpdate.Status.UP_TO_DATE || !remoteRefName.startsWith(Constants.R_TAGS)) { update.put(KEY_COMMIT_MESSAGE, remoteRefUpdate.getMessage()); update.put(KEY_RESULT, status.name()); TrackingRefUpdate refUpdate = remoteRefUpdate.getTrackingRefUpdate(); if (refUpdate != null) { update.put(KEY_REMOTENAME, Repository.shortenRefName(refUpdate.getLocalName())); update.put(KEY_LOCALNAME, Repository.shortenRefName(refUpdate.getRemoteName())); } else { update.put(KEY_REMOTENAME, Repository.shortenRefName(remoteRefUpdate.getSrcRef())); update.put(KEY_LOCALNAME, Repository.shortenRefName(remoteRefUpdate.getRemoteName())); } updates.add(update); } if (status != RemoteRefUpdate.Status.OK) { commandOutput = buildPushFailedMessage(request, remoteRefUpdate, currentBranch); } } } return pushResponseDto.withCommandOutput(commandOutput).withUpdates(updates); }
From source file:org.eclipse.egit.core.op.PushOperationResult.java
License:Open Source License
/** * Derive push operation specification from this push operation result. * <p>/*from ww w . ja va 2 s . c om*/ * Specification is created basing on URIs of remote repositories in this * result that completed without connection errors, and remote ref updates * from push results. * <p> * This method is targeted to provide support for 2-stage push, where first * operation is dry run for user confirmation and second one is a real * operation. * * @param requireUnchanged * if true, newly created copies of remote ref updates have * expected old object id set to previously advertised ref value * (remote ref won't be updated if it change in the mean time), * if false, newly create copies of remote ref updates have * expected object id set up as in this result source * specification. * @return derived specification for another push operation. * @throws IOException * when some previously locally available source ref is not * available anymore, or some error occurred during creation * locally tracking ref update. * */ public PushOperationSpecification deriveSpecification(final boolean requireUnchanged) throws IOException { final PushOperationSpecification spec = new PushOperationSpecification(); for (final URIish uri : getURIs()) { final PushResult pr = getPushResult(uri); if (pr == null) continue; final Collection<RemoteRefUpdate> oldUpdates = pr.getRemoteUpdates(); final ArrayList<RemoteRefUpdate> newUpdates = new ArrayList<RemoteRefUpdate>(oldUpdates.size()); for (final RemoteRefUpdate rru : oldUpdates) { final ObjectId expectedOldObjectId; if (requireUnchanged) { final Ref advertisedRef = getPushResult(uri).getAdvertisedRef(rru.getRemoteName()); if (advertisedRef == null) expectedOldObjectId = ObjectId.zeroId(); else expectedOldObjectId = advertisedRef.getObjectId(); } else expectedOldObjectId = rru.getExpectedOldObjectId(); final RemoteRefUpdate newRru = new RemoteRefUpdate(rru, expectedOldObjectId); newUpdates.add(newRru); } spec.addURIRefUpdates(uri, newUpdates); } return spec; }
From source file:org.eclipse.egit.core.op.PushOperationResult.java
License:Open Source License
/** * This implementation returns true if all following conditions are met: * <ul>/* w w w . j a v a 2 s . c om*/ * <li>both objects result have the same set successfully connected * repositories (URIs) - unsuccessful connections are discarded, AND <li> * remote ref updates must match for each successful connection in sense of * equal remoteName, equal status and equal newObjectId value.</li> * </ul> * * @see Object#equals(Object) * @param obj * other push operation result to compare to. * @return true if object is equal to this one in terms of conditions * described above, false otherwise. */ @Override public boolean equals(final Object obj) { if (obj == this) return true; if (!(obj instanceof PushOperationResult)) return false; final PushOperationResult other = (PushOperationResult) obj; // Check successful connections/URIs two-ways: final Set<URIish> otherURIs = other.getURIs(); for (final URIish uri : getURIs()) { if (isSuccessfulConnection(uri) && (!otherURIs.contains(uri) || !other.isSuccessfulConnection(uri))) return false; } for (final URIish uri : other.getURIs()) { if (other.isSuccessfulConnection(uri) && (!urisEntries.containsKey(uri) || !isSuccessfulConnection(uri))) return false; } for (final URIish uri : getURIs()) { if (!isSuccessfulConnection(uri)) continue; final PushResult otherPushResult = other.getPushResult(uri); for (final RemoteRefUpdate rru : getPushResult(uri).getRemoteUpdates()) { final RemoteRefUpdate otherRru = otherPushResult.getRemoteUpdate(rru.getRemoteName()); if (otherRru == null) return false; if (otherRru.getStatus() != rru.getStatus() || otherRru.getNewObjectId() != rru.getNewObjectId()) return false; } } return true; }
From source file:org.eclipse.egit.ui.internal.push.RefUpdateContentProvider.java
License:Open Source License
public Object[] getElements(final Object inputElement) { if (inputElement == null) return new RefUpdateElement[0]; final PushOperationResult result = (PushOperationResult) inputElement; final SortedMap<String, String> dstToSrc = new TreeMap<String, String>(); for (final URIish uri : result.getURIs()) { if (result.isSuccessfulConnection(uri)) { for (final RemoteRefUpdate rru : result.getPushResult(uri).getRemoteUpdates()) dstToSrc.put(rru.getRemoteName(), rru.getSrcRef()); // Assuming that each repository received the same ref updates, // we need only one to get these ref names. break; }//ww w . ja v a2 s . co m } // Transforming PushOperationResult model to row-wise one. final RefUpdateElement elements[] = new RefUpdateElement[dstToSrc.size()]; int i = 0; for (final Entry<String, String> entry : dstToSrc.entrySet()) elements[i++] = new RefUpdateElement(result, entry.getValue(), entry.getKey()); return elements; }