Search in sources :

Example 11 with PatchSet

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

the class ConsistencyCheckerIT method duplicatePatchSetRevisions.

@Test
public void duplicatePatchSetRevisions() throws Exception {
    ChangeNotes notes = insertChange();
    PatchSet ps1 = psUtil.current(notes);
    notes = incrementPatchSet(notes, serverSideTestRepo.getRevWalk().parseCommit(ps1.commitId()));
    assertProblems(notes, null, problem("Multiple patch sets pointing to " + ps1.commitId().name() + ": [1, 2]"));
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with PatchSet

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

the class ConsistencyCheckerIT method expectedMergedCommitIsOldPatchSetOfSameChange.

@Test
public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception {
    ChangeNotes notes = insertChange();
    ObjectId commitId1 = psUtil.current(notes).commitId();
    notes = incrementPatchSet(notes);
    PatchSet ps2 = psUtil.current(notes);
    serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(serverSideTestRepo.getRevWalk().parseCommit(commitId1));
    FixInput fix = new FixInput();
    fix.expectMergedAs = commitId1.name();
    assertProblems(notes, fix, problem("No patch set found for merged commit " + commitId1.name(), FIXED, "Marked change as merged"), problem("Expected merge commit " + commitId1.name() + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Deleted patch set"), problem("Expected merge commit " + commitId1.name() + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Inserted as patch set 3"));
    notes = reload(notes);
    PatchSet.Id psId3 = PatchSet.id(notes.getChangeId(), 3);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId3);
    assertThat(notes.getChange().isMerged()).isTrue();
    assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps2.id(), psId3);
    assertThat(psUtil.get(notes, psId3).commitId()).isEqualTo(commitId1);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) TestChanges.newPatchSet(com.google.gerrit.testing.TestChanges.newPatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) FixInput(com.google.gerrit.extensions.api.changes.FixInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with PatchSet

use of com.google.gerrit.entities.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.id());
    assertThat(notes.getChange().getSubject()).isEqualTo("Change subject");
    assertThat(notes.getChange().getOriginalSubject()).isEqualTo("Change subject");
    assertThat(ps1.id()).isEqualTo(PatchSet.id(c.getId(), 1));
    assertThat(ps1.uploader()).isEqualTo(changeOwner.getAccountId());
    // ps2 by other user
    RevCommit commit = incrementPatchSet(c, otherUser);
    notes = newNotes(c);
    PatchSet ps2 = notes.getCurrentPatchSet();
    assertThat(ps2.id()).isEqualTo(PatchSet.id(c.getId(), 2));
    assertThat(notes.getChange().getSubject()).isEqualTo("PS2");
    assertThat(notes.getChange().getOriginalSubject()).isEqualTo("Change subject");
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(ps2.id());
    assertThat(ps2.commitId()).isNotEqualTo(ps1.commitId());
    assertThat(ps2.commitId()).isEqualTo(commit);
    assertThat(ps2.uploader()).isEqualTo(otherUser.getAccountId());
    assertThat(ps2.createdOn()).isEqualTo(notes.getChange().getLastUpdatedOn());
    // comment on ps1, current patch set is still ps2
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setPatchSetId(ps1.id());
    update.setChangeMessage("Comment on old patch set.");
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getChange().currentPatchSetId()).isEqualTo(ps2.id());
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 14 with PatchSet

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

the class ChangeNotesTest method commitChangeNotesUnique.

@Test
public void commitChangeNotesUnique() throws Exception {
    // PatchSetId -> ObjectId 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();
    StorageException e = assertThrows(StorageException.class, () -> newNotes(c));
    assertCause(e, ConfigInvalidException.class, "Multiple revisions parsed for patch set 1:" + " " + commit.name() + " and " + ps.commitId().name());
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 15 with PatchSet

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

the class SubmitByRebaseAlwaysIT method rebaseInvokesChangeMessageModifiers.

@Test
public void rebaseInvokesChangeMessageModifiers() throws Throwable {
    ChangeMessageModifier modifier1 = (msg, orig, tip, dest) -> msg + "This-change-before-rebase: " + orig.name() + "\n";
    ChangeMessageModifier modifier2 = (msg, orig, tip, dest) -> msg + "Previous-step-tip: " + tip.name() + "\n";
    ChangeMessageModifier modifier3 = (msg, orig, tip, dest) -> msg + "Dest: " + dest.shortName() + "\n";
    try (Registration registration = extensionRegistry.newRegistration().add(modifier1).add(modifier2).add(modifier3)) {
        ImmutableList<PushOneCommit.Result> changes = submitWithRebase(admin);
        ChangeData cd1 = changes.get(0).getChange();
        ChangeData cd2 = changes.get(1).getChange();
        assertThat(cd2.patchSets()).hasSize(2);
        String change1CurrentCommit = cd1.currentPatchSet().commitId().name();
        String change2Ps1Commit = cd2.patchSet(PatchSet.id(cd2.getId(), 1)).commitId().name();
        assertThat(gApi.changes().id(cd2.getId().get()).revision(2).commit(false).message).isEqualTo("Change 2\n\n" + ("Change-Id: " + cd2.change().getKey() + "\n") + ("Reviewed-on: " + urlFormatter.get().getChangeViewUrl(project, cd2.getId()).get() + "\n") + "Reviewed-by: Administrator <admin@example.com>\n" + ("This-change-before-rebase: " + change2Ps1Commit + "\n") + ("Previous-step-tip: " + change1CurrentCommit + "\n") + "Dest: master\n");
    }
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) Test(org.junit.Test)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11