use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class RefAdvertisementIT method receivePackOmitsMissingObject.
@Test
public void receivePackOmitsMissingObject() throws Exception {
String rev = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
try (Repository repo = repoManager.openRepository(project)) {
TestRepository<?> tr = new TestRepository<>(repo);
String subject = "Subject for missing commit";
Change c = new Change(c3.change());
PatchSet.Id psId = new PatchSet.Id(c3.getId(), 2);
c.setCurrentPatchSet(psId, subject, c.getOriginalSubject());
if (notesMigration.changePrimaryStorage() == PrimaryStorage.REVIEW_DB) {
PatchSet ps = TestChanges.newPatchSet(psId, rev, admin.getId());
db.patchSets().insert(Collections.singleton(ps));
db.changes().update(Collections.singleton(c));
}
if (notesMigration.commitChangeWrites()) {
PersonIdent committer = serverIdent.get();
PersonIdent author = noteUtil.newIdent(accountCache.get(admin.getId()).getAccount(), committer.getWhen(), committer, anonymousCowardName);
tr.branch(RefNames.changeMetaRef(c3.getId())).commit().author(author).committer(committer).message("Update patch set " + psId.get() + "\n" + "\n" + "Patch-set: " + psId.get() + "\n" + "Commit: " + rev + "\n" + "Subject: " + subject + "\n").create();
}
indexer.index(db, c.getProject(), c.getId());
}
assertThat(getReceivePackRefs().additionalHaves()).containsExactly(obj(c4, 1));
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class SubmitOnPushIT method mergeMultipleOnPushToBranchWithNewPatchset.
@Test
public void mergeMultipleOnPushToBranchWithNewPatchset() throws Exception {
grant(project, "refs/heads/master", Permission.PUSH);
// Create 2 changes.
ObjectId initialHead = getRemoteHead();
PushOneCommit.Result r1 = createChange("Change 1", "a", "a");
r1.assertOkStatus();
PushOneCommit.Result r2 = createChange("Change 2", "b", "b");
r2.assertOkStatus();
RevCommit c1_1 = r1.getCommit();
RevCommit c2_1 = r2.getCommit();
PatchSet.Id psId1_1 = r1.getPatchSetId();
PatchSet.Id psId2_1 = r2.getPatchSetId();
assertThat(c1_1.getParent(0)).isEqualTo(initialHead);
assertThat(c2_1.getParent(0)).isEqualTo(c1_1);
// Amend both changes.
testRepo.reset(initialHead);
RevCommit c1_2 = testRepo.branch("HEAD").commit().message(c1_1.getShortMessage() + "v2").insertChangeId(r1.getChangeId().substring(1)).create();
RevCommit c2_2 = testRepo.cherryPick(c2_1);
// Push directly to branch.
assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
ChangeData cd2 = r2.getChange();
assertThat(cd2.change().getStatus()).isEqualTo(Change.Status.MERGED);
PatchSet.Id psId2_2 = cd2.change().currentPatchSetId();
assertThat(psId2_2.get()).isEqualTo(2);
assertThat(cd2.patchSet(psId2_1).getRevision().get()).isEqualTo(c2_1.name());
assertThat(cd2.patchSet(psId2_2).getRevision().get()).isEqualTo(c2_2.name());
ChangeData cd1 = r1.getChange();
assertThat(cd1.change().getStatus()).isEqualTo(Change.Status.MERGED);
PatchSet.Id psId1_2 = cd1.change().currentPatchSetId();
assertThat(psId1_2.get()).isEqualTo(2);
assertThat(cd1.patchSet(psId1_1).getRevision().get()).isEqualTo(c1_1.name());
assertThat(cd1.patchSet(psId1_2).getRevision().get()).isEqualTo(c1_2.name());
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class DeleteDraftPatchSetIT method deleteDraftPS1.
@Test
public void deleteDraftPS1() throws Exception {
String changeId = createDraftChangeWith2PS();
ReviewInput rin = new ReviewInput();
rin.message = "Change message";
CommentInput cin = new CommentInput();
cin.line = 1;
cin.patchSet = 1;
cin.path = PushOneCommit.FILE_NAME;
cin.side = Side.REVISION;
cin.message = "Inline comment";
rin.comments = new HashMap<>();
rin.comments.put(cin.path, ImmutableList.of(cin));
gApi.changes().id(changeId).revision(1).review(rin);
ChangeData cd = getChange(changeId);
PatchSet.Id delPsId = new PatchSet.Id(cd.getId(), 1);
PatchSet ps = cd.patchSet(delPsId);
deletePatchSet(changeId, ps);
cd = getChange(changeId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(Iterables.getOnlyElement(cd.patchSets()).getId().get()).isEqualTo(2);
// Other entities based on deleted patch sets are also deleted.
for (ChangeMessage m : cd.messages()) {
assertThat(m.getPatchSetId()).named(m.toString()).isNotEqualTo(delPsId);
}
for (Comment c : cd.publishedComments()) {
assertThat(c.key.patchSetId).named(c.toString()).isNotEqualTo(delPsId.get());
}
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class DeleteDraftPatchSetIT method deleteDraftPS2.
@Test
public void deleteDraftPS2() throws Exception {
String changeId = createDraftChangeWith2PS();
ReviewInput rin = new ReviewInput();
rin.message = "Change message";
CommentInput cin = new CommentInput();
cin.line = 1;
cin.patchSet = 1;
cin.path = PushOneCommit.FILE_NAME;
cin.side = Side.REVISION;
cin.message = "Inline comment";
rin.comments = new HashMap<>();
rin.comments.put(cin.path, ImmutableList.of(cin));
gApi.changes().id(changeId).revision(1).review(rin);
ChangeData cd = getChange(changeId);
PatchSet.Id delPsId = new PatchSet.Id(cd.getId(), 2);
PatchSet ps = cd.patchSet(delPsId);
deletePatchSet(changeId, ps);
cd = getChange(changeId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(Iterables.getOnlyElement(cd.patchSets()).getId().get()).isEqualTo(1);
// Other entities based on deleted patch sets are also deleted.
for (ChangeMessage m : cd.messages()) {
assertThat(m.getPatchSetId()).named(m.toString()).isNotEqualTo(delPsId);
}
for (Comment c : cd.publishedComments()) {
assertThat(c.key.patchSetId).named(c.toString()).isNotEqualTo(delPsId.get());
}
}
use of com.google.gerrit.reviewdb.client.PatchSet 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());
}
Aggregations