Search in sources :

Example 36 with PatchSet

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

the class ChangeNotesTest method commitChangeNotesUnique.

@Test
public void commitChangeNotesUnique() throws Exception {
    // PatchSetId -> RevId must be a one to one mapping
    Change c = newChange();
    ChangeNotes notes = newNotes(c);
    PatchSet ps = notes.getCurrentPatchSet();
    assertThat(ps).isNotNull();
    // new revId for the same patch set, ps1
    ChangeUpdate update = newUpdate(c, changeOwner);
    RevCommit commit = tr.commit().message("PS1 again").create();
    update.setCommit(rw, commit);
    update.commit();
    try {
        notes = newNotes(c);
        fail("Expected IOException");
    } catch (OrmException e) {
        assertCause(e, ConfigInvalidException.class, "Multiple revisions parsed for patch set 1:" + " RevId{" + commit.name() + "} and " + ps.getRevision().get());
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 37 with PatchSet

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

the class ChangeNotesTest method patchSetChangeNotes.

@Test
public void patchSetChangeNotes() throws Exception {
    Change c = newChange();
    // ps1 created by newChange()
    ChangeNotes notes = newNotes(c);
    PatchSet ps1 = notes.getCurrentPatchSet();
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(ps1.getId());
    assertThat(notes.getChange().getSubject()).isEqualTo("Change subject");
    assertThat(notes.getChange().getOriginalSubject()).isEqualTo("Change subject");
    assertThat(ps1.getId()).isEqualTo(new PatchSet.Id(c.getId(), 1));
    assertThat(ps1.getUploader()).isEqualTo(changeOwner.getAccountId());
    // ps2 by other user
    RevCommit commit = incrementPatchSet(c, otherUser);
    notes = newNotes(c);
    PatchSet ps2 = notes.getCurrentPatchSet();
    assertThat(ps2.getId()).isEqualTo(new PatchSet.Id(c.getId(), 2));
    assertThat(notes.getChange().getSubject()).isEqualTo("PS2");
    assertThat(notes.getChange().getOriginalSubject()).isEqualTo("Change subject");
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(ps2.getId());
    assertThat(ps2.getRevision().get()).isNotEqualTo(ps1.getRevision());
    assertThat(ps2.getRevision().get()).isEqualTo(commit.name());
    assertThat(ps2.getUploader()).isEqualTo(otherUser.getAccountId());
    assertThat(ps2.getCreatedOn()).isEqualTo(notes.getChange().getLastUpdatedOn());
    // comment on ps1, current patch set is still ps2
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setPatchSetId(ps1.getId());
    update.setChangeMessage("Comment on old patch set.");
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(ps2.getId());
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 38 with PatchSet

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

the class ChangeBundleTest method diffPatchSetsIgnoresLeadingAndTrailingWhitespaceInReviewDbDescriptions.

@Test
public void diffPatchSetsIgnoresLeadingAndTrailingWhitespaceInReviewDbDescriptions() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSet ps1 = new PatchSet(new PatchSet.Id(c.getId(), 1));
    ps1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps1.setUploader(accountId);
    ps1.setCreatedOn(TimeUtil.nowTs());
    ps1.setDescription(" abc ");
    PatchSet ps2 = clone(ps1);
    ps2.setDescription("abc");
    // Both ReviewDb, exact match required.
    ChangeBundle b1 = new ChangeBundle(c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "description differs for PatchSet.Id " + ps1.getId() + ": { abc } != {abc}");
    // Whitespace in ReviewDb description is ignored.
    b1 = new ChangeBundle(c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
    // Must match except for the leading/trailing whitespace.
    PatchSet ps3 = clone(ps1);
    ps3.setDescription("cba");
    b1 = new ChangeBundle(c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c, messages(), patchSets(ps3), approvals(), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "description differs for PatchSet.Id " + ps1.getId() + ": { abc } != {cba}");
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevId(com.google.gerrit.reviewdb.client.RevId) Test(org.junit.Test)

Example 39 with PatchSet

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

the class AbstractSubmitByRebase method repairChangeStateAfterFailure.

@Test
public void repairChangeStateAfterFailure() throws Exception {
    // In NoteDb-only mode, repo and meta updates are atomic (at least in InMemoryRepository).
    assume().that(notesMigration.disableChangeReviewDb()).isFalse();
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
    submit(change.getChangeId());
    RevCommit headAfterFirstSubmit = getRemoteHead();
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
    Change.Id id2 = change2.getChange().getId();
    SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
    submit(change2.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
    RevCommit headAfterFailedSubmit = getRemoteHead();
    // Bad: ref advanced but change wasn't updated.
    PatchSet.Id psId1 = new PatchSet.Id(id2, 1);
    PatchSet.Id psId2 = new PatchSet.Id(id2, 2);
    ChangeInfo info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    assertThat(getPatchSet(psId2)).isNull();
    ObjectId rev2;
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        ObjectId rev1 = repo.exactRef(psId1.toRefName()).getObjectId();
        assertThat(rev1).isNotNull();
        rev2 = repo.exactRef(psId2.toRefName()).getObjectId();
        assertThat(rev2).isNotNull();
        assertThat(rev2).isNotEqualTo(rev1);
        assertThat(rw.parseCommit(rev2).getParent(0)).isEqualTo(headAfterFirstSubmit);
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
    }
    submit(change2.getChangeId());
    RevCommit headAfterSecondSubmit = getRemoteHead();
    assertThat(headAfterSecondSubmit).isEqualTo(headAfterFailedSubmit);
    // Change status and patch set entities were updated, and branch tip stayed
    // the same.
    info = gApi.changes().id(id2.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(2);
    PatchSet ps2 = getPatchSet(psId2);
    assertThat(ps2).isNotNull();
    assertThat(ps2.getRevision().get()).isEqualTo(rev2.name());
    assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully rebased and submitted as " + rev2.name() + " by Administrator");
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
    }
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name(), change2.getChangeId(), headAfterSecondSubmit.name());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) Repository(org.eclipse.jgit.lib.Repository) GitUtil.getChangeId(com.google.gerrit.acceptance.GitUtil.getChangeId) ObjectId(org.eclipse.jgit.lib.ObjectId) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 40 with PatchSet

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

the class ConsistencyCheckerIT method insertMissingPatchSet.

private PatchSet insertMissingPatchSet(ChangeControl ctl, String rev) throws Exception {
    // Don't use BatchUpdate since we're manually updating the meta ref rather
    // than using ChangeUpdate.
    String subject = "Subject for missing commit";
    Change c = new Change(ctl.getChange());
    PatchSet.Id psId = nextPatchSetId(ctl);
    c.setCurrentPatchSet(psId, subject, c.getOriginalSubject());
    PatchSet ps = newPatchSet(psId, rev, adminId);
    if (PrimaryStorage.of(c) == PrimaryStorage.REVIEW_DB) {
        db.patchSets().insert(singleton(ps));
        db.changes().update(singleton(c));
    }
    addNoteDbCommit(c.getId(), "Update patch set " + psId.get() + "\n" + "\n" + "Patch-set: " + psId.get() + "\n" + "Commit: " + rev + "\n" + "Subject: " + subject + "\n");
    indexer.index(db, c.getProject(), c.getId());
    return ps;
}
Also used : TestChanges.newPatchSet(com.google.gerrit.testutil.TestChanges.newPatchSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change)

Aggregations

PatchSet (com.google.gerrit.reviewdb.client.PatchSet)124 Change (com.google.gerrit.reviewdb.client.Change)51 Test (org.junit.Test)44 ObjectId (org.eclipse.jgit.lib.ObjectId)35 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)27 RevCommit (org.eclipse.jgit.revwalk.RevCommit)26 Repository (org.eclipse.jgit.lib.Repository)21 RevId (com.google.gerrit.reviewdb.client.RevId)20 ChangeControl (com.google.gerrit.server.project.ChangeControl)20 ChangeData (com.google.gerrit.server.query.change.ChangeData)19 OrmException (com.google.gwtorm.server.OrmException)19 Timestamp (java.sql.Timestamp)18 RevWalk (org.eclipse.jgit.revwalk.RevWalk)15 Project (com.google.gerrit.reviewdb.client.Project)14 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)11 TestChanges.newPatchSet (com.google.gerrit.testutil.TestChanges.newPatchSet)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)10 Account (com.google.gerrit.reviewdb.client.Account)10