Search in sources :

Example 26 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb.

@Test
public void diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb() throws Exception {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    c1.setTopic("");
    Change c2 = clone(c1);
    c2.setTopic(null);
    // Both ReviewDb, exact match required.
    ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {} != {null}");
    // Topic ignored if ReviewDb is empty and NoteDb is null.
    b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    // Exact match still required if NoteDb has empty value (not realistic).
    b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {} != {null}");
    // Null is not equal to a non-empty string.
    Change c3 = clone(c1);
    c3.setTopic("topic");
    b1 = new ChangeBundle(c3, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ": {topic} != {null}");
    // Null is equal to a string that is all whitespace.
    Change c4 = clone(c1);
    c4.setTopic("  ");
    b1 = new ChangeBundle(c4, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 27 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeIT method createNewDraftPatchSetOnDraftChange.

@Test
public void createNewDraftPatchSetOnDraftChange() throws Exception {
    // Create new project with clean permissions
    Project.NameKey p = createProject("addPatchSet4");
    // Clone separate repositories of the same project as admin and as user
    TestRepository<?> adminTestRepo = cloneProject(p, admin);
    TestRepository<?> userTestRepo = cloneProject(p, user);
    // Block default permission
    block(p, "refs/for/*", Permission.ADD_PATCH_SET, REGISTERED_USERS);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/drafts/master");
    r1.assertOkStatus();
    // Add user as reviewer
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r1.getChangeId()).addReviewer(in);
    // Fetch change
    GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", user, userTestRepo);
    r2.assertErrorStatus("cannot add patch set to " + r1.getChange().getId().id + ".");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SetParentIT method setInvalidParent_Conflict.

@Test
public void setInvalidParent_Conflict() throws Exception {
    RestResponse r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(project.get()));
    r.assertConflict();
    r.consume();
    Project.NameKey child = createProject("child", project, true);
    r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(child.get()));
    r.assertConflict();
    r.consume();
    String grandchild = createProject("grandchild", child, true).get();
    r = adminRestSession.put("/projects/" + project.get() + "/parent", newParentInput(grandchild));
    r.assertConflict();
    r.consume();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class CherryPickCommit method applyImpl.

@Override
public ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, CommitResource rsrc, CherryPickInput input) throws OrmException, IOException, UpdateException, RestApiException {
    RevCommit commit = rsrc.getCommit();
    String message = Strings.nullToEmpty(input.message).trim();
    input.message = message.isEmpty() ? commit.getFullMessage() : message;
    String destination = Strings.nullToEmpty(input.destination).trim();
    input.parent = input.parent == null ? 1 : input.parent;
    if (destination.isEmpty()) {
        throw new BadRequestException("destination must be non-empty");
    }
    ProjectControl projectControl = rsrc.getProject();
    Capable capable = projectControl.canPushToAtLeastOneRef();
    if (capable != Capable.OK) {
        throw new AuthException(capable.getMessage());
    }
    String refName = RefNames.fullName(destination);
    RefControl refControl = projectControl.controlForRef(refName);
    if (!refControl.canUpload()) {
        throw new AuthException("Not allowed to cherry pick " + commit + " to " + destination);
    }
    Project.NameKey project = projectControl.getProject().getNameKey();
    try {
        Change.Id cherryPickedChangeId = cherryPickChange.cherryPick(updateFactory, null, null, null, null, project, commit, input, refName, refControl);
        return json.noOptions().format(project, cherryPickedChangeId);
    } catch (InvalidChangeOperationException e) {
        throw new BadRequestException(e.getMessage());
    } catch (IntegrationException e) {
        throw new ResourceConflictException(e.getMessage());
    }
}
Also used : InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) IntegrationException(com.google.gerrit.server.git.IntegrationException) RefControl(com.google.gerrit.server.project.RefControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.reviewdb.client.Change) ProjectControl(com.google.gerrit.server.project.ProjectControl) Project(com.google.gerrit.reviewdb.client.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Capable(com.google.gerrit.common.data.Capable) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 30 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ApplyFix method apply.

@Override
public Response<EditInfo> apply(FixResource fixResource, Void nothing) throws AuthException, OrmException, ResourceConflictException, IOException, ResourceNotFoundException, PermissionBackendException {
    RevisionResource revisionResource = fixResource.getRevisionResource();
    Project.NameKey project = revisionResource.getProject();
    ProjectState projectState = revisionResource.getControl().getProjectControl().getProjectState();
    PatchSet patchSet = revisionResource.getPatchSet();
    ObjectId patchSetCommitId = ObjectId.fromString(patchSet.getRevision().get());
    try (Repository repository = gitRepositoryManager.openRepository(project)) {
        List<TreeModification> treeModifications = fixReplacementInterpreter.toTreeModifications(repository, projectState, patchSetCommitId, fixResource.getFixReplacements());
        ChangeEdit changeEdit = changeEditModifier.combineWithModifiedPatchSetTree(repository, revisionResource.getControl(), patchSet, treeModifications);
        return Response.ok(changeEditJson.toEditInfo(changeEdit, false));
    } catch (InvalidChangeOperationException e) {
        throw new ResourceConflictException(e.getMessage());
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) Repository(org.eclipse.jgit.lib.Repository) ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ObjectId(org.eclipse.jgit.lib.ObjectId) ProjectState(com.google.gerrit.server.project.ProjectState) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) TreeModification(com.google.gerrit.server.edit.tree.TreeModification)

Aggregations

Project (com.google.gerrit.reviewdb.client.Project)93 Test (org.junit.Test)37 Change (com.google.gerrit.reviewdb.client.Change)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 Branch (com.google.gerrit.reviewdb.client.Branch)21 Account (com.google.gerrit.reviewdb.client.Account)19 Config (org.eclipse.jgit.lib.Config)18 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)17 Repository (org.eclipse.jgit.lib.Repository)17 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 SubmoduleSectionParser (com.google.gerrit.server.util.SubmoduleSectionParser)14 IOException (java.io.IOException)14 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)13 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)13 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)12 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)12 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12