Example usage for org.eclipse.jgit.transport RemoteRefUpdate getMessage

List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate getMessage

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RemoteRefUpdate getMessage.

Prototype

public String getMessage() 

Source Link

Document

Get message describing reasons of status when needed/possible; may be null.

Usage

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.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 w w  w . j  av  a2  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  ww w .  j  a  v  a 2 s .  com
        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: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 ww  .j  a va  2  s.c o  m*/
        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 .co  m*/
        builder.append(update.getMessage() + " " + update.getRemoteName() + " " + update.getNewObjectId());
    }
    return builder.toString();
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitLabelingSupport.java

License:Apache License

@NotNull
private String push(@NotNull String label, @NotNull String version, @NotNull GitVcsRoot gitRoot,
        @NotNull Repository r, @NotNull Ref tagRef, @NotNull RevisionsInfo revisionsInfo)
        throws VcsException, IOException {
    long pushStart = System.currentTimeMillis();
    final Transport tn = myTransportFactory.createTransport(r, gitRoot.getRepositoryPushURL(),
            gitRoot.getAuthSettings(), myConfig.getPushTimeoutSeconds());
    PushConnection c = null;/*from   w  ww. j  ava  2s  .co  m*/
    try {
        c = tn.openPush();
        RemoteRefUpdate ru = new RemoteRefUpdate(r, tagRef.getName(), tagRef.getObjectId(), tagRef.getName(),
                false, null, null);
        PreparePackFunction preparePack = null;
        if (c instanceof BasePackPushConnection) {
            final RevTag tagObject = getTagObject(r, tagRef);
            if (tagObject != null) {
                preparePack = new PreparePackFunction(tagObject, revisionsInfo);
                ((BasePackPushConnection) c).setPreparePack(preparePack);
            } else {
                LOG.debug("Cannot locate the " + tagRef.getName() + " tag object, don't use pack heuristic");
            }
        }
        c.push(NullProgressMonitor.INSTANCE, Collections.singletonMap(tagRef.getName(), ru));
        LOG.info("Tag  " + label + "=" + version + " was pushed with status " + ru.getStatus() + " for "
                + gitRoot.debugInfo() + " in " + (System.currentTimeMillis() - pushStart) + "ms"
                + (preparePack != null ? " (prepare pack " + preparePack.getPreparePackDurationMillis() + "ms)"
                        : ""));
        switch (ru.getStatus()) {
        case UP_TO_DATE:
        case OK:
            break;
        default:
            String msg = ru.getMessage();
            throw new VcsException("The remote '" + label + "' tag was not created" + ", status: "
                    + ru.getStatus() + (!isEmpty(msg) ? ", message: " + msg : ""));
        }
        return label;
    } finally {
        if (c != null)
            c.close();
        tn.close();
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport.java

License:Apache License

@NotNull
private MergeResult doMerge(@NotNull OperationContext context, @NotNull GitVcsRoot gitRoot,
        @NotNull Repository db, @NotNull String srcRevision, @NotNull String dstBranch, @NotNull String message,
        @NotNull MergeOptions options) throws IOException, VcsException {
    RefSpec spec = new RefSpec().setSource(GitUtils.expandRef(dstBranch))
            .setDestination(GitUtils.expandRef(dstBranch)).setForceUpdate(true);
    myCommitLoader.fetch(db, gitRoot.getRepositoryFetchURL(), asList(spec),
            new FetchSettings(gitRoot.getAuthSettings()));
    RevCommit srcCommit = myCommitLoader.findCommit(db, srcRevision);
    if (srcCommit == null)
        srcCommit = myCommitLoader.loadCommit(context, gitRoot, srcRevision);

    Ref dstRef = db.getRef(dstBranch);
    RevCommit dstBranchLastCommit = myCommitLoader.loadCommit(context, gitRoot, dstRef.getObjectId().name());
    ObjectId commitId;//from   w w w .  j ava2s  .c  om
    try {
        commitId = mergeCommits(gitRoot, db, srcCommit, dstBranchLastCommit, message, options);
    } catch (MergeFailedException e) {
        LOG.debug("Merge error, root " + gitRoot + ", revision " + srcRevision + ", destination " + dstBranch,
                e);
        return MergeResult.createMergeError(e.getConflicts());
    }

    synchronized (myRepositoryManager.getWriteLock(gitRoot.getRepositoryDir())) {
        final Transport tn = myTransportFactory.createTransport(db, gitRoot.getRepositoryPushURL(),
                gitRoot.getAuthSettings(), myPluginConfig.getPushTimeoutSeconds());
        try {
            final PushConnection c = tn.openPush();
            try {
                RemoteRefUpdate ru = new RemoteRefUpdate(db, null, commitId, GitUtils.expandRef(dstBranch),
                        false, null, dstBranchLastCommit);
                c.push(NullProgressMonitor.INSTANCE,
                        Collections.singletonMap(GitUtils.expandRef(dstBranch), ru));
                switch (ru.getStatus()) {
                case UP_TO_DATE:
                case OK:
                    return MergeResult.createMergeSuccessResult();
                default:
                    return MergeResult.createMergeError("Push failed, " + ru.getMessage());
                }
            } finally {
                c.close();
            }
        } catch (IOException e) {
            LOG.debug("Error while pushing a merge commit, root " + gitRoot + ", revision " + srcRevision
                    + ", destination " + dstBranch, e);
            throw e;
        } finally {
            tn.close();
        }
    }
}

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  w w w .  j  a  v  a2 s  .c  o  m
        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.che.git.impl.jgit.JGitConnection.java

License:Open Source License

private String buildPushFailedMessage(final PushRequest request, final RemoteRefUpdate remoteRefUpdate,
        final String currentBranch) {
    String message;//from   www . ja  v a 2  s  .  com
    if (remoteRefUpdate.getStatus() == RemoteRefUpdate.Status.UP_TO_DATE) {
        message = INFO_PUSH_ATTEMPT_IGNORED_UP_TO_DATE;
    } else {
        String refspec = currentBranch + BRANCH_REFSPEC_SEPERATOR
                + request.getRefSpec().get(0).split(REFSPEC_COLON)[1];
        if (remoteRefUpdate.getMessage() != null) {
            message = String.format(ERROR_PUSH_ATTEMPT_FAILED_WITHMSG, refspec, request.getRemote(),
                    remoteRefUpdate.getStatus(), remoteRefUpdate.getMessage());
        } else {
            message = String.format(ERROR_PUSH_ATTEMPT_FAILED_WITHOUTMSG, refspec, request.getRemote(),
                    remoteRefUpdate.getStatus());
        }
    }
    return message;
}

From source file:org.eclipse.egit.ui.internal.push.PushJob.java

License:Open Source License

@Override
protected IStatus getDeferredStatus() {
    for (URIish uri : operationResult.getURIs()) {
        PushResult outcome = operationResult.getPushResult(uri);
        for (RemoteRefUpdate update : outcome.getRemoteUpdates()) {
            switch (update.getStatus()) {
            case NOT_ATTEMPTED:
            case UP_TO_DATE:
            case OK:
                continue;
            default:
                return new Status(IStatus.ERROR, Activator.getPluginId(), IStatus.ERROR, update.getMessage(),
                        null);/*from   w  w  w  .jav  a  2 s  . com*/
            }
        }
    }
    return super.getDeferredStatus();
}