use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.
the class ChangeIT method changeNoParentToOneParent.
@Test
@TestProjectInput(createEmptyCommit = false)
public void changeNoParentToOneParent() throws Exception {
// create initial commit with no parent and push it as change, so that patch
// set 1 has no parent
RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
String id = GitUtil.getChangeId(testRepo, c).get();
testRepo.reset(c);
PushResult pr = pushHead(testRepo, "refs/for/master", false);
assertPushOk(pr, "refs/for/master");
ChangeInfo change = gApi.changes().id(id).get();
assertThat(change.revisions.get(change.currentRevision).commit.parents).isEmpty();
// create another initial commit with no parent and push it directly into
// the remote repository
c = testRepo.amend(c.getId()).message("Initial Empty Commit").create();
testRepo.reset(c);
pr = pushHead(testRepo, "refs/heads/master", false);
assertPushOk(pr, "refs/heads/master");
// create a successor commit and push it as second patch set to the change,
// so that patch set 2 has 1 parent
RevCommit c2 = testRepo.commit().message("Initial commit").parent(c).insertChangeId(id.substring(1)).create();
testRepo.reset(c2);
pr = pushHead(testRepo, "refs/for/master", false);
assertPushOk(pr, "refs/for/master");
change = gApi.changes().id(id).get();
RevisionInfo rev = change.revisions.get(change.currentRevision);
assertThat(rev.commit.parents).hasSize(1);
assertThat(rev.commit.parents.get(0).commit).isEqualTo(c.name());
// check that change kind is correctly detected as REWORK
assertThat(rev.kind).isEqualTo(ChangeKind.REWORK);
}
use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.
the class ChangeIT method queryChangesOptions.
@Test
public void queryChangesOptions() throws Exception {
PushOneCommit.Result r = createChange();
ChangeInfo result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).get());
assertThat(result.labels).isNull();
assertThat(result.messages).isNull();
assertThat(result.actions).isNull();
assertThat(result.revisions).isNull();
result = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOptions(ALL_REVISIONS, CHANGE_ACTIONS, CURRENT_ACTIONS, DETAILED_LABELS, MESSAGES).get());
assertThat(Iterables.getOnlyElement(result.labels.keySet())).isEqualTo(LabelId.CODE_REVIEW);
assertThat(result.messages).hasSize(1);
assertThat(result.actions).isNotEmpty();
RevisionInfo rev = Iterables.getOnlyElement(result.revisions.values());
assertThat(rev._number).isEqualTo(r.getPatchSetId().get());
assertThat(rev.created).isNotNull();
assertThat(rev.uploader._accountId).isEqualTo(admin.id().get());
assertThat(rev.ref).isEqualTo(r.getPatchSetId().toRefName());
assertThat(rev.actions).isNotEmpty();
}
use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
List<String> footers = commitToCherryPick.getFooterLines("Change-Id");
assertThat(footers).hasSize(1);
String changeId = footers.get(0);
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef\n\nChange-Id: %s\n", changeId);
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
// No change was found in destination branch with the provided Change-Id.
assertThat(cherryPickResult._number).isGreaterThan(changeToCherryPick._number);
assertThat(cherryPickResult.changeId).isEqualTo(changeId);
assertThat(cherryPickResult.revisions).hasSize(1);
assertThat(cherryPickResult.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", commitToCherryPick.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
// Cherry-pick of is not set, because the source change was not provided.
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
}
use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitToExistingCherryPickedChange.
@Test
public void cherryPickCommitToExistingCherryPickedChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange("refs/for/" + destBranch);
ChangeInfo existingDestChange = info(r.getChangeId());
r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: %s\n", existingDestChange.changeId);
input.allowConflicts = true;
input.allowEmpty = true;
// Use RevisionAPI to submit initial cherryPick.
ChangeInfo cherryPickResult = gApi.changes().id(changeToCherryPick.changeId).current().cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
// Cherry-pick was set.
assertThat(cherryPickResult.cherryPickOfChange).isEqualTo(changeToCherryPick._number);
assertThat(cherryPickResult.cherryPickOfPatchSet).isEqualTo(1);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
// Use CommitApi to update the cherryPick change.
cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
assertThat(cherryPickResult.messages).hasSize(3);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 2.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 3.");
// Cherry-pick was reset to empty value.
assertThat(cherryPickResult._number).isEqualTo(existingDestChange._number);
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
}
use of com.google.gerrit.extensions.common.RevisionInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithoutChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithoutChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = "it goes to foo branch";
RevCommit commitToCherryPick = createNewCommitWithoutChangeId("refs/heads/master", "a.txt", "content");
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", commitToCherryPick.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
CommitInfo commitInfo = revInfo.commit;
assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + cherryPickResult.changeId + "\n");
}
Aggregations