use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionUnrelatedWithTwoMergeCommits.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionUnrelatedWithTwoMergeCommits() throws Exception {
String topic = "topic";
PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
approve(firstResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
approve(secondResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result thirdResult = createChange(testRepo, "master", "third change", "c.txt", "message", topic);
approve(thirdResult.getChangeId());
gApi.changes().id(firstResult.getChangeId()).current().submit();
// put the head on the most recent merge commit.
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master:merge")).call();
testRepo.reset("merge");
// Create another change that should be ignored. The reverts should be rebased on top of the
// merge commit.
PushOneCommit.Result fourthResult = createChange(testRepo, "master", "fourth change", "d.txt", "message", topic);
approve(fourthResult.getChangeId());
gApi.changes().id(fourthResult.getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
Collections.reverse(revertChanges);
assertThat(revertChanges.get(0).current().files().get("c.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("b.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(2).current().files().get("a.txt").linesDeleted).isEqualTo(1);
String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
String sha1SecondRevert = revertChanges.get(1).current().commit(false).commit;
// parent of the first revert is the merged change of previous changes.
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge \"third change\"");
// Next reverts would stack on top of the previous ones.
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
assertThat(revertChanges).hasSize(3);
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(3);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class AbandonIT method notAbandonedIfMergeableWhenMergeableOperatorIsEnabled.
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void notAbandonedIfMergeableWhenMergeableOperatorIsEnabled() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
// create 2 changes
int id1 = createChange().getChange().getId().get();
int id2 = createChange().getChange().getId().get();
// create 2 changes that conflict with each other
testRepo.reset(initial);
int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
testRepo.reset(initial);
int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
// make all 4 previously created changes older than 1 week
TestTimeUtil.incrementClock(7 * 24, HOURS);
// create 1 new change that will not be abandoned because it is not older than 1 week
testRepo.reset(initial);
ChangeData cd = createChange().getChange();
int id5 = cd.getId().get();
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
assertThat(query("is:abandoned")).isEmpty();
// submit one of the conflicting changes
gApi.changes().id(id3).current().review(ReviewInput.approve());
gApi.changes().id(id3).current().submit();
assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
assertThat(toChangeNumbers(query("-is:mergeable"))).containsExactly(id4);
abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5, id2, id1);
assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class AbandonIT method abandonedIfMergeableWhenMergeableOperatorIsDisabled.
/**
* When indexing mergeable is disabled then the abandonIfMergeable option is ineffective and the
* auto abandon behaves as though it were set to its default value (true).
*/
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "NEVER")
public void abandonedIfMergeableWhenMergeableOperatorIsDisabled() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
// create 2 changes
int id1 = createChange().getChange().getId().get();
int id2 = createChange().getChange().getId().get();
// create 2 changes that conflict with each other
testRepo.reset(initial);
int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
testRepo.reset(initial);
int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
// make all 4 previously created changes older than 1 week
TestTimeUtil.incrementClock(7 * 24, HOURS);
// create 1 new change that will not be abandoned because it is not older than 1 week
testRepo.reset(initial);
ChangeData cd = createChange().getChange();
int id5 = cd.getId().get();
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
assertThat(query("is:abandoned")).isEmpty();
// submit one of the conflicting changes
gApi.changes().id(id3).current().review(ReviewInput.approve());
gApi.changes().id(id3).current().submit();
assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
BadRequestException thrown = assertThrows(BadRequestException.class, () -> query("-is:mergeable"));
assertThat(thrown).hasMessageThat().contains("operator is not supported");
abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5);
assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4, id2, id1);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class DisablePrivateChangesIT method createPrivateChangeWithDisablePrivateChangesTrue.
@Test
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
public void createPrivateChangeWithDisablePrivateChangesTrue() throws Exception {
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
input.isPrivate = true;
MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().create(input));
assertThat(thrown).hasMessageThat().contains("private changes are disabled");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class DisablePrivateChangesIT method setPrivateWithDisablePrivateChangesTrue.
@Test
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
public void setPrivateWithDisablePrivateChangesTrue() throws Exception {
PushOneCommit.Result result = createChange();
MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().id(result.getChangeId()).setPrivate(true, "set private"));
assertThat(thrown).hasMessageThat().contains("private changes are disabled");
}
Aggregations