use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefSetForDifferentWriteRequests.
@Test
public void xGerritUpdatedRefSetForDifferentWriteRequests() throws Exception {
Result change = createChange();
String origin = adminRestSession.url();
String project = change.getChange().project().get();
String metaRef = RefNames.changeMetaRef(change.getChange().getId());
ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
RestResponse response = adminRestSession.putWithHeaders("/changes/" + change.getChangeId() + "/topic", /* content= */
"A", new BasicHeader(ORIGIN, origin), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
assertThat(gApi.changes().id(change.getChangeId()).topic()).isEqualTo("A");
ObjectId firstMetaRefSha1 = getMetaRefSha1(change);
// Meta ref updated because of topic update.
assertThat(response.getHeader(X_GERRIT_UPDATED_REF)).isEqualTo(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), originalMetaRefSha1.getName(), firstMetaRefSha1.getName()));
response = adminRestSession.putWithHeaders("/changes/" + change.getChangeId() + "/topic", /* content= */
"B", new BasicHeader(ORIGIN, origin), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
assertThat(gApi.changes().id(change.getChangeId()).topic()).isEqualTo("B");
ObjectId secondMetaRefSha1 = getMetaRefSha1(change);
// Meta ref updated again because of another topic update.
assertThat(response.getHeader(X_GERRIT_UPDATED_REF)).isEqualTo(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), firstMetaRefSha1.getName(), secondMetaRefSha1.getName()));
// Ensure the meta ref SHA-1 changed for the project~metaRef which means we return different
// X-Gerrit-UpdatedRef headers.
assertThat(secondMetaRefSha1).isNotEqualTo(firstMetaRefSha1);
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmitTopic.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void xGerritUpdatedRefSetMultipleHeadersForSubmitTopic() throws Exception {
String secondProject = "secondProject";
projectOperations.newProject().name(secondProject).create();
TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
String topic = "topic";
String branch = "refs/heads/master";
Result change1 = createChange(testRepo, branch, "first change", "a.txt", "message", topic);
Result change2 = createChange(secondRepo, branch, "second change", "b.txt", "message", topic);
String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
Project.NameKey project1 = change1.getChange().project();
Project.NameKey project2 = change2.getChange().project();
try (Repository repository1 = repoManager.openRepository(project1);
Repository repository2 = repoManager.openRepository(project2)) {
ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
ObjectId originalDestinationBranchSha1Project1 = repository1.resolve(change1.getChange().change().getDest().branch());
ObjectId originalDestinationBranchSha1Project2 = repository2.resolve(change2.getChange().change().getDest().branch());
RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
String branchSha1Project1 = repository1.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
String branchSha1Project2 = repository2.getRefDatabase().exactRef(change2.getChange().change().getDest().branch()).getObjectId().name();
// During submit, all relevant meta refs of the latest patchset are updated + the destination
// branch/es.
// TODO(paiking): This doesn't work well for torn submissions: If the changes are in
// different projects in the same topic, and we tried to submit those changes together, it's
// possible that the first submission only submitted one of the changes, and then the retry
// submitted the other change. If that happens, when the user retries, they will not get the
// meta ref updates for the change that got submitted on the previous submission attempt.
// Ideally, submit should be idempotent and always return all meta refs on all submission
// attempts.
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(branch), originalDestinationBranchSha1Project1.getName(), branchSha1Project1), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(branch), originalDestinationBranchSha1Project2.getName(), branchSha1Project2));
}
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class AbandonRestoreIT method withMessage.
@Test
public void withMessage() throws Exception {
Result result = createChange();
String commit = result.getCommit().name();
executeCmd(commit, "abandon", "'abandon it'");
executeCmd(commit, "restore", "'restore it'");
assertChangeMessages(result.getChangeId(), ImmutableList.of("Uploaded patch set 1.", "Abandoned\n\nabandon it", "Restored\n\nrestore it"));
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class AbandonRestoreIT method withoutMessage.
@Test
public void withoutMessage() throws Exception {
Result result = createChange();
String commit = result.getCommit().name();
executeCmd(commit, "abandon", null);
executeCmd(commit, "restore", null);
assertChangeMessages(result.getChangeId(), ImmutableList.of("Uploaded patch set 1.", "Abandoned", "Restored"));
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class CommitIT method includedInMergedChange_filtersOutNonVisibleBranches.
@Test
public void includedInMergedChange_filtersOutNonVisibleBranches() throws Exception {
Result baseChange = createAndSubmitChange("refs/for/master");
createBranch(BranchNameKey.create(project, "test-branch-1"));
createBranch(BranchNameKey.create(project, "test-branch-2"));
createAndSubmitChange("refs/for/test-branch-1");
createAndSubmitChange("refs/for/test-branch-2");
assertThat(getIncludedIn(baseChange.getCommit().getId()).branches).containsExactly("master", "test-branch-1", "test-branch-2");
projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/test-branch-1").group(REGISTERED_USERS)).update();
assertThat(getIncludedIn(baseChange.getCommit().getId()).branches).containsExactly("master", "test-branch-2");
}
Aggregations