Search in sources :

Example 1 with CommitValidationMessage

use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.

the class CancellationIT method handleClientDisconnectedForPush.

@Test
public void handleClientDisconnectedForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // to the client.
            throw new RequestCancelledException(RequestStateProvider.Reason.CLIENT_CLOSED_REQUEST, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Client Closed Request");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with CommitValidationMessage

use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.

the class CancellationIT method handleServerDeadlineExceededForPush.

@Test
public void handleServerDeadlineExceededForPush() throws Exception {
    CommitValidationListener commitValidationListener = new CommitValidationListener() {

        @Override
        public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent) throws CommitValidationException {
            // Simulate an exceeded deadline by throwing RequestCancelledException.
            throw new RequestCancelledException(RequestStateProvider.Reason.SERVER_DEADLINE_EXCEEDED, /* cancellationMessage= */
            null);
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(commitValidationListener)) {
        PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
        PushOneCommit.Result r = push.to("refs/heads/master");
        r.assertErrorStatus("Server Deadline Exceeded");
    }
}
Also used : CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) RequestCancelledException(com.google.gerrit.server.cancellation.RequestCancelledException) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with CommitValidationMessage

use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.

the class SubmitRequirementExpressionsValidator method validateSubmitRequirementExpressions.

private ImmutableList<CommitValidationMessage> validateSubmitRequirementExpressions(Collection<SubmitRequirement> submitRequirements) {
    List<CommitValidationMessage> validationMessages = new ArrayList<>();
    for (SubmitRequirement submitRequirement : submitRequirements) {
        validateSubmitRequirementExpression(validationMessages, submitRequirement, submitRequirement.submittabilityExpression(), ProjectConfig.KEY_SR_SUBMITTABILITY_EXPRESSION);
        submitRequirement.applicabilityExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_APPLICABILITY_EXPRESSION));
        submitRequirement.overrideExpression().ifPresent(expression -> validateSubmitRequirementExpression(validationMessages, submitRequirement, expression, ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION));
    }
    return ImmutableList.copyOf(validationMessages);
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ArrayList(java.util.ArrayList) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage)

Example 4 with CommitValidationMessage

use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.

the class ReceiveCommits method rejectImplicitMerges.

private void rejectImplicitMerges(Set<RevCommit> mergedParents) throws IOException {
    try (TraceTimer traceTimer = newTimer("rejectImplicitMerges")) {
        if (!mergedParents.isEmpty()) {
            Ref targetRef = receivePackRefCache.exactRef(magicBranch.dest.branch());
            if (targetRef != null) {
                RevWalk rw = receivePack.getRevWalk();
                RevCommit tip = rw.parseCommit(targetRef.getObjectId());
                boolean containsImplicitMerges = true;
                for (RevCommit p : mergedParents) {
                    containsImplicitMerges &= !rw.isMergedInto(p, tip);
                }
                if (containsImplicitMerges) {
                    rw.reset();
                    for (RevCommit p : mergedParents) {
                        rw.markStart(p);
                    }
                    rw.markUninteresting(tip);
                    RevCommit c;
                    while ((c = rw.next()) != null) {
                        rw.parseBody(c);
                        messages.add(new CommitValidationMessage("Implicit Merge of " + abbreviateName(c, rw.getObjectReader()) + " " + c.getShortMessage(), ValidationMessage.Type.ERROR));
                    }
                    reject(magicBranch.cmd, "implicit merges detected");
                }
            }
        }
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with CommitValidationMessage

use of com.google.gerrit.server.git.validators.CommitValidationMessage in project gerrit by GerritCodeReview.

the class ReceiveCommits method rejectImplicitMerges.

private void rejectImplicitMerges(Set<RevCommit> mergedParents) throws IOException {
    if (!mergedParents.isEmpty()) {
        Ref targetRef = allRefs.get(magicBranch.ctl.getRefName());
        if (targetRef != null) {
            RevWalk rw = rp.getRevWalk();
            RevCommit tip = rw.parseCommit(targetRef.getObjectId());
            boolean containsImplicitMerges = true;
            for (RevCommit p : mergedParents) {
                containsImplicitMerges &= !rw.isMergedInto(p, tip);
            }
            if (containsImplicitMerges) {
                rw.reset();
                for (RevCommit p : mergedParents) {
                    rw.markStart(p);
                }
                rw.markUninteresting(tip);
                RevCommit c;
                while ((c = rw.next()) != null) {
                    rw.parseBody(c);
                    messages.add(new CommitValidationMessage("ERROR: Implicit Merge of " + c.abbreviate(7).name() + " " + c.getShortMessage(), false));
                }
                reject(magicBranch.cmd, "implicit merges detected");
            }
        }
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)9 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)5 CommitReceivedEvent (com.google.gerrit.server.events.CommitReceivedEvent)5 CommitValidationListener (com.google.gerrit.server.git.validators.CommitValidationListener)5 Test (org.junit.Test)5 Ref (org.eclipse.jgit.lib.Ref)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)1 SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)1 CommitValidationException (com.google.gerrit.server.git.validators.CommitValidationException)1 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)1 DiffNotAvailableException (com.google.gerrit.server.patch.DiffNotAvailableException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1