Search in sources :

Example 26 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class PRED_change_branch_1 method exec.

@Override
public Operation exec(Prolog engine) throws PrologException {
    engine.setB0();
    Term a1 = arg1.dereference();
    BranchNameKey name = StoredValues.getChange(engine).getDest();
    if (!a1.unify(SymbolTerm.create(name.branch()), engine.trail)) {
        return engine.fail();
    }
    return cont;
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) Term(com.googlecode.prolog_cafe.lang.Term) SymbolTerm(com.googlecode.prolog_cafe.lang.SymbolTerm)

Example 27 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class AbstractSubmitByRebase method submitChangesAfterBranchOnSecond.

@Test
public void submitChangesAfterBranchOnSecond() throws Throwable {
    RevCommit initialHead = projectOperations.project(project).getHead("master");
    PushOneCommit.Result change = createChange();
    approve(change.getChangeId());
    PushOneCommit.Result change2 = createChange();
    approve(change2.getChangeId());
    Project.NameKey project = change2.getChange().change().getProject();
    BranchNameKey branch = BranchNameKey.create(project, "branch");
    createBranchWithRevision(branch, change2.getCommit().getName());
    gApi.changes().id(change2.getChangeId()).current().submit();
    assertMerged(change2.getChangeId());
    assertMerged(change.getChangeId());
    RevCommit newHead = projectOperations.project(this.project).getHead("master");
    assertRefUpdatedEvents(initialHead, newHead);
    assertChangeMergedEvents(change.getChangeId(), newHead.name(), change2.getChangeId(), newHead.name());
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 28 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class ReceiveCommits method parseCreate.

private void parseCreate(ReceiveCommand cmd) throws PermissionBackendException, NoSuchProjectException, IOException {
    try (TraceTimer traceTimer = newTimer("parseCreate")) {
        if (repo.resolve(cmd.getRefName()) != null) {
            reject(cmd, String.format("Cannot create ref '%s' because it already exists.", cmd.getRefName()));
            return;
        }
        RevObject obj;
        try {
            obj = receivePack.getRevWalk().parseAny(cmd.getNewId());
        } catch (IOException e) {
            throw new StorageException(String.format("Invalid object %s for %s creation", cmd.getNewId().name(), cmd.getRefName()), e);
        }
        logger.atFine().log("Creating %s", cmd);
        if (isHead(cmd) && !isCommit(cmd)) {
            return;
        }
        BranchNameKey branch = BranchNameKey.create(project.getName(), cmd.getRefName());
        try {
            // Must pass explicit user instead of injecting a provider into CreateRefControl, since
            // Provider<CurrentUser> within ReceiveCommits will always return anonymous.
            createRefControl.checkCreateRef(Providers.of(user), receivePack.getRepository(), branch, obj);
        } catch (AuthException denied) {
            rejectProhibited(cmd, denied);
            return;
        } catch (ResourceConflictException denied) {
            reject(cmd, "prohibited by Gerrit: " + denied.getMessage());
            return;
        }
        if (validRefOperation(cmd)) {
            validateRegularPushCommits(BranchNameKey.create(project.getNameKey(), cmd.getRefName()), cmd);
        }
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RevObject(org.eclipse.jgit.revwalk.RevObject) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 29 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class Move method apply.

@Override
public Response<ChangeInfo> apply(ChangeResource rsrc, MoveInput input) throws RestApiException, UpdateException, PermissionBackendException, IOException {
    if (!moveEnabled) {
        // behavior. See: https://bugs.chromium.org/p/gerrit/issues/detail?id=9877
        throw new MethodNotAllowedException("move changes endpoint is disabled");
    }
    Change change = rsrc.getChange();
    Project.NameKey project = rsrc.getProject();
    IdentifiedUser caller = rsrc.getUser().asIdentifiedUser();
    if (input.destinationBranch == null) {
        throw new BadRequestException("destination branch is required");
    }
    input.destinationBranch = RefNames.fullName(input.destinationBranch);
    if (!change.isNew()) {
        throw new ResourceConflictException("Change is " + ChangeUtil.status(change));
    }
    BranchNameKey newDest = BranchNameKey.create(project, input.destinationBranch);
    if (change.getDest().equals(newDest)) {
        throw new ResourceConflictException("Change is already destined for the specified branch");
    }
    // Not allowed to move if the current patch set is locked.
    psUtil.checkPatchSetNotLocked(rsrc.getNotes());
    // Only administrators are allowed to keep all labels at their own risk.
    try {
        if (input.keepAllVotes) {
            permissionBackend.user(caller).check(GlobalPermission.ADMINISTRATE_SERVER);
        }
    } catch (AuthException denied) {
        throw new AuthException("move is not permitted with keepAllVotes option", denied);
    }
    // Move requires abandoning this change, and creating a new change.
    try {
        rsrc.permissions().check(ABANDON);
        permissionBackend.user(caller).ref(newDest).check(CREATE_CHANGE);
    } catch (AuthException denied) {
        throw new AuthException("move not permitted", denied);
    }
    projectCache.get(project).orElseThrow(illegalState(project)).checkStatePermitsWrite();
    Op op = new Op(input);
    try (BatchUpdate u = updateFactory.create(project, caller, TimeUtil.now())) {
        u.addOp(change.getId(), op);
        u.execute();
    }
    return Response.ok(json.noOptions().format(op.getChange()));
}
Also used : Project(com.google.gerrit.entities.Project) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 30 with BranchNameKey

use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.

the class ChangeIT method customCommitFooters.

@Test
public void customCommitFooters() throws Exception {
    PushOneCommit.Result change = createChange();
    ChangeInfo actual;
    ChangeMessageModifier link = new ChangeMessageModifier() {

        @Override
        public String onSubmit(String newCommitMessage, RevCommit original, RevCommit mergeTip, BranchNameKey destination) {
            assertThat(original.getName()).isNotEqualTo(mergeTip.getName());
            return newCommitMessage + "Custom: " + destination.branch();
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(link)) {
        actual = gApi.changes().id(change.getChangeId()).get(ALL_REVISIONS, COMMIT_FOOTERS);
    }
    List<String> footers = new ArrayList<>(Arrays.asList(actual.revisions.get(change.getCommit().getName()).commitWithFooters.split("\\n")));
    // remove subject + blank line
    footers.remove(0);
    footers.remove(0);
    List<String> expectedFooters = Arrays.asList("Change-Id: " + change.getChangeId(), "Reviewed-on: " + canonicalWebUrl.get() + "c/" + project.get() + "/+/" + change.getChange().getId(), "Custom: refs/heads/master");
    assertThat(footers).containsExactlyElementsIn(expectedFooters);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ArrayList(java.util.ArrayList) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BranchNameKey (com.google.gerrit.entities.BranchNameKey)75 Test (org.junit.Test)48 Project (com.google.gerrit.entities.Project)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)25 Config (org.eclipse.jgit.lib.Config)19 SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 AuthException (com.google.gerrit.extensions.restapi.AuthException)13 Change (com.google.gerrit.entities.Change)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 StorageException (com.google.gerrit.exceptions.StorageException)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Repository (org.eclipse.jgit.lib.Repository)9 PatchSet (com.google.gerrit.entities.PatchSet)8 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)8 HashMap (java.util.HashMap)7 Ref (org.eclipse.jgit.lib.Ref)7