Search in sources :

Example 16 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class SubmitByCherryPickIT method submitIdenticalTree.

@Test
@TestProjectInput(useContentMerge = InheritableBoolean.TRUE)
public void submitIdenticalTree() throws Exception {
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change1 = createChange("Change 1", "a.txt", "a");
    testRepo.reset(initialHead);
    PushOneCommit.Result change2 = createChange("Change 2", "a.txt", "a");
    submit(change1.getChangeId());
    RevCommit headAfterFirstSubmit = getRemoteHead();
    assertThat(headAfterFirstSubmit.getShortMessage()).isEqualTo("Change 1");
    submit(change2.getChangeId(), new SubmitInput(), null, null);
    assertThat(getRemoteHead()).isEqualTo(headAfterFirstSubmit);
    ChangeInfo info2 = get(change2.getChangeId());
    assertThat(info2.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(Iterables.getLast(info2.messages).message).isEqualTo(CommitMergeStatus.SKIPPED_IDENTICAL_TREE.getMessage());
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change1.getChangeId(), headAfterFirstSubmit.name(), change2.getChangeId(), headAfterFirstSubmit.name());
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Test(org.junit.Test)

Example 17 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class SubmitByCherryPickIT 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());
    // Change status and patch set entities were updated, and branch tip stayed
    // the same.
    RevCommit headAfterSecondSubmit = getRemoteHead();
    assertThat(headAfterSecondSubmit).isEqualTo(headAfterFailedSubmit);
    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 cherry-picked 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) 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 18 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class SubmitByFastForwardIT 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();
    PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
    Change.Id id = change.getChange().getId();
    SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
    submit(change.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
    // Bad: ref advanced but change wasn't updated.
    PatchSet.Id psId = new PatchSet.Id(id, 1);
    ChangeInfo info = gApi.changes().id(id.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.NEW);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    ObjectId rev;
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        rev = repo.exactRef(psId.toRefName()).getObjectId();
        assertThat(rev).isNotNull();
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev);
    }
    submit(change.getChangeId());
    // Change status was updated, and branch tip stayed the same.
    info = gApi.changes().id(id.get()).get();
    assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
    assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
    assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully merged by Administrator");
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev);
    }
    assertRefUpdatedEvents();
    assertChangeMergedEvents(change.getChangeId(), getRemoteHead().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) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) TestSubmitInput(com.google.gerrit.server.change.Submit.TestSubmitInput) Test(org.junit.Test)

Example 19 with SubmitInput

use of com.google.gerrit.extensions.api.changes.SubmitInput in project gerrit by GerritCodeReview.

the class ReceiveCommits method submit.

private void submit(Collection<CreateRequest> create, Collection<ReplaceRequest> replace) throws OrmException, RestApiException {
    Map<ObjectId, Change> bySha = Maps.newHashMapWithExpectedSize(create.size() + replace.size());
    for (CreateRequest r : create) {
        checkNotNull(r.change, "cannot submit new change %s; op may not have run", r.changeId);
        bySha.put(r.commit, r.change);
    }
    for (ReplaceRequest r : replace) {
        bySha.put(r.newCommitId, r.notes.getChange());
    }
    Change tipChange = bySha.get(magicBranch.cmd.getNewId());
    checkNotNull(tipChange, "tip of push does not correspond to a change; found these changes: %s", bySha);
    logDebug("Processing submit with tip change {} ({})", tipChange.getId(), magicBranch.cmd.getNewId());
    try (MergeOp op = mergeOpFactory.create(batchUpdateFactory)) {
        op.merge(db, tipChange, user, false, new SubmitInput(), false);
    }
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change)

Aggregations

SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)19 Test (org.junit.Test)16 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 Change (com.google.gerrit.reviewdb.client.Change)7 TestSubmitInput (com.google.gerrit.server.change.Submit.TestSubmitInput)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)4 Repository (org.eclipse.jgit.lib.Repository)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)4 Project (com.google.gerrit.reviewdb.client.Project)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)3 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 GerritConfig (com.google.gerrit.acceptance.GerritConfig)1 GitUtil.getChangeId (com.google.gerrit.acceptance.GitUtil.getChangeId)1 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)1 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)1 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)1