use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbstractSubmitOnPush method mergeOnPushToBranchWithOldPatchset.
@Test
public void mergeOnPushToBranchWithOldPatchset() throws Exception {
projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/heads/master").group(adminGroupUuid())).update();
PushOneCommit.Result r = pushTo("refs/for/master");
r.assertOkStatus();
RevCommit c1 = r.getCommit();
PatchSet.Id psId1 = r.getPatchSetId();
String changeId = r.getChangeId();
assertThat(psId1.get()).isEqualTo(1);
r = amendChange(changeId);
ChangeData cd = r.getChange();
PatchSet.Id psId2 = cd.change().currentPatchSetId();
assertThat(psId2.changeId()).isEqualTo(psId1.changeId());
assertThat(psId2.get()).isEqualTo(2);
testRepo.reset(c1);
assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
cd = changeDataFactory.create(project, psId1.changeId());
Change c = cd.change();
assertThat(c.isMerged()).isTrue();
assertThat(c.currentPatchSetId()).isEqualTo(psId1);
assertThat(cd.patchSets().stream().map(PatchSet::id).collect(toList())).containsExactly(psId1, psId2);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbstractPushForReview method accidentallyPushNewPatchSetDirectlyToBranch.
private Change.Id accidentallyPushNewPatchSetDirectlyToBranch() throws Exception {
PushOneCommit.Result r = createChange();
RevCommit ps1Commit = r.getCommit();
Change c = r.getChange().change();
RevCommit ps2Commit;
try (Repository repo = repoManager.openRepository(project);
TestRepository<?> tr = new TestRepository<>(repo)) {
// Create a new patch set of the change directly in Gerrit's repository,
// without pushing it. In reality it's more likely that the client would
// create and push this behind Gerrit's back (e.g. an admin accidentally
// using direct ssh access to the repo), but that's harder to do in tests.
ps2Commit = tr.branch("refs/heads/master").commit().message(ps1Commit.getShortMessage() + " v2").insertChangeId(r.getChangeId().substring(1)).create();
}
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master")).call();
testRepo.reset(ps2Commit);
ChangeData cd = byCommit(ps1Commit);
assertThat(cd.change().isNew()).isTrue();
assertThat(getPatchSetRevisions(cd)).containsExactlyEntriesIn(ImmutableMap.of(1, ps1Commit.name()));
return c.getId();
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbstractSubmitOnPush method mergeOnPushToBranch.
@Test
public void mergeOnPushToBranch() throws Exception {
projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/heads/master").group(adminGroupUuid())).update();
PushOneCommit.Result r = push("refs/for/master", PushOneCommit.SUBJECT, "a.txt", "some content");
r.assertOkStatus();
git().push().setRefSpecs(new RefSpec(r.getCommit().name() + ":refs/heads/master")).call();
assertCommit(project, "refs/heads/master");
ChangeData cd = Iterables.getOnlyElement(queryProvider.get().byKey(Change.key(r.getChangeId())));
RevCommit c = r.getCommit();
PatchSet.Id psId = cd.currentPatchSet().id();
assertThat(psId.get()).isEqualTo(1);
assertThat(cd.change().isMerged()).isTrue();
assertSubmitApproval(psId);
assertThat(cd.patchSets()).hasSize(1);
assertThat(cd.patchSet(psId).commitId()).isEqualTo(c);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbstractSubmitOnPush method mergeMultipleOnPushToBranchWithNewPatchset.
@Test
public void mergeMultipleOnPushToBranchWithNewPatchset() throws Exception {
projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/heads/master").group(adminGroupUuid())).update();
// Create 2 changes.
ObjectId initialHead = projectOperations.project(project).getHead("master");
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().isMerged()).isTrue();
PatchSet.Id psId2_2 = cd2.change().currentPatchSetId();
assertThat(psId2_2.get()).isEqualTo(2);
assertThat(cd2.patchSet(psId2_1).commitId()).isEqualTo(c2_1);
assertThat(cd2.patchSet(psId2_2).commitId()).isEqualTo(c2_2);
ChangeData cd1 = r1.getChange();
assertThat(cd1.change().isMerged()).isTrue();
PatchSet.Id psId1_2 = cd1.change().currentPatchSetId();
assertThat(psId1_2.get()).isEqualTo(2);
assertThat(cd1.patchSet(psId1_1).commitId()).isEqualTo(c1_1);
assertThat(cd1.patchSet(psId1_2).commitId()).isEqualTo(c1_2);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeFieldTest method tolerateNullValuesForInsertion.
@Test
public void tolerateNullValuesForInsertion() {
Project.NameKey project = Project.nameKey("project");
ChangeData cd = ChangeData.createForTest(project, Change.id(1), 1, ObjectId.zeroId());
assertThat(ChangeField.ADDED.setIfPossible(cd, new FakeStoredValue(null))).isTrue();
}
Aggregations