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());
}
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());
}
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());
}
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);
}
}
Aggregations