use of com.google.gerrit.extensions.api.changes.ChangeApi in project gerrit by GerritCodeReview.
the class RevisionIT method patchWithPath.
@Test
public void patchWithPath() throws Exception {
PushOneCommit.Result r = createChange();
ChangeApi changeApi = gApi.changes().id(r.getChangeId());
BinaryResult bin = changeApi.revision(r.getCommit().name()).patch(FILE_NAME);
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String res = new String(os.toByteArray(), UTF_8);
assertThat(res).isEqualTo(PATCH_FILE_ONLY);
exception.expect(ResourceNotFoundException.class);
exception.expectMessage("File not found: nonexistent-file.");
changeApi.revision(r.getCommit().name()).patch("nonexistent-file");
}
use of com.google.gerrit.extensions.api.changes.ChangeApi in project gerrit by GerritCodeReview.
the class RevisionIT method patch.
@Test
public void patch() throws Exception {
PushOneCommit.Result r = createChange();
ChangeApi changeApi = gApi.changes().id(r.getChangeId());
BinaryResult bin = changeApi.revision(r.getCommit().name()).patch();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String res = new String(os.toByteArray(), UTF_8);
ChangeInfo change = changeApi.get();
RevisionInfo rev = change.revisions.get(change.currentRevision);
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
String date = df.format(rev.commit.author.date);
assertThat(res).isEqualTo(String.format(PATCH, r.getCommit().name(), date, r.getChangeId()));
}
use of com.google.gerrit.extensions.api.changes.ChangeApi in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickwithNoTopic.
@Test
public void cherryPickwithNoTopic() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = "it goes to stable branch";
gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
assertThat(cherry.get().topic).isNull();
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
}
use of com.google.gerrit.extensions.api.changes.ChangeApi in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToSameBranchWithRebase.
@Test
public void cherryPickToSameBranchWithRebase() throws Exception {
// Push a new change, then merge it
PushOneCommit.Result baseChange = createChange();
String triplet = project.get() + "~master~" + baseChange.getChangeId();
RevisionApi baseRevision = gApi.changes().id(triplet).current();
baseRevision.review(ReviewInput.approve());
baseRevision.submit();
// Push a new change (change 1)
PushOneCommit.Result r1 = createChange();
// Push another new change (change 2)
String subject = "Test change\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, subject, "another_file.txt", "another content");
PushOneCommit.Result r2 = push.to("refs/for/master");
// Change 2's parent should be change 1
assertThat(r2.getCommit().getParents()[0].name()).isEqualTo(r1.getCommit().name());
// Cherry pick change 2 onto the same branch
triplet = project.get() + "~master~" + r2.getChangeId();
ChangeApi orig = gApi.changes().id(triplet);
CherryPickInput in = new CherryPickInput();
in.destination = "master";
in.message = subject;
ChangeApi cherry = orig.revision(r2.getCommit().name()).cherryPick(in);
ChangeInfo cherryInfo = cherry.get();
assertThat(cherryInfo.messages).hasSize(2);
Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
// Parent of change 2 should now be the change that was merged, i.e.
// change 2 is rebased onto the head of the master branch.
String newParent = cherryInfo.revisions.get(cherryInfo.currentRevision).commit.parents.get(0).commit;
assertThat(newParent).isEqualTo(baseChange.getCommit().name());
}
use of com.google.gerrit.extensions.api.changes.ChangeApi in project gerrit by GerritCodeReview.
the class SubmitByMergeIfNecessaryIT method gerritWorkflow.
@Test
public void gerritWorkflow() throws Exception {
RevCommit initialHead = getRemoteHead();
// We'll setup a master and a stable branch.
// Then we create a change to be applied to master, which is
// then cherry picked back to stable. The stable branch will
// be merged up into master again.
gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
// Push a change to master
PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo, "small fix", "a.txt", "2");
PushOneCommit.Result change = push.to("refs/for/master");
submit(change.getChangeId());
RevCommit headAfterFirstSubmit = getRemoteLog(project, "master").get(0);
assertThat(headAfterFirstSubmit.getShortMessage()).isEqualTo(change.getCommit().getShortMessage());
// Now cherry pick to stable
CherryPickInput in = new CherryPickInput();
in.destination = "stable";
in.message = "This goes to stable as well\n" + headAfterFirstSubmit.getFullMessage();
ChangeApi orig = gApi.changes().id(change.getChangeId());
String cherryId = orig.current().cherryPick(in).id();
gApi.changes().id(cherryId).current().review(ReviewInput.approve());
gApi.changes().id(cherryId).current().submit();
// Create the merge locally
RevCommit stable = getRemoteHead(project, "stable");
RevCommit master = getRemoteHead(project, "master");
testRepo.git().fetch().call();
testRepo.git().branchCreate().setName("stable").setStartPoint(stable).call();
testRepo.git().branchCreate().setName("master").setStartPoint(master).call();
RevCommit merge = testRepo.commit().parent(master).parent(stable).message("Merge stable into master").insertChangeId().create();
testRepo.branch("refs/heads/master").update(merge);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/master:refs/for/master")).call();
String changeId = GitUtil.getChangeId(testRepo, merge).get();
approve(changeId);
submit(changeId);
RevCommit headAfterSecondSubmit = getRemoteLog(project, "master").get(0);
assertThat(headAfterSecondSubmit.getShortMessage()).isEqualTo(merge.getShortMessage());
assertRefUpdatedEvents(initialHead, headAfterFirstSubmit, headAfterFirstSubmit, headAfterSecondSubmit);
assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name(), changeId, headAfterSecondSubmit.name());
}
Aggregations