use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method createBranchWithRevision.
protected BranchApi createBranchWithRevision(Branch.NameKey branch, String revision) throws Exception {
BranchInput in = new BranchInput();
in.revision = revision;
return gApi.projects().name(branch.getParentKey().get()).branch(branch.get()).create(in);
}
use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitWithCommitAndItsMergeCommitTogether.
@Test
public void submitWithCommitAndItsMergeCommitTogether() throws Exception {
assume().that(isSubmitWholeTopicEnabled()).isTrue();
RevCommit initialHead = getRemoteHead();
// Create a stable branch and bootstrap it.
gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo, "initial commit", "a.txt", "a");
PushOneCommit.Result change = push.to("refs/heads/stable");
RevCommit stable = getRemoteHead(project, "stable");
RevCommit master = getRemoteHead(project, "master");
assertThat(master).isEqualTo(initialHead);
assertThat(stable).isEqualTo(change.getCommit());
testRepo.git().fetch().call();
testRepo.git().branchCreate().setName("stable").setStartPoint(stable).call();
testRepo.git().branchCreate().setName("master").setStartPoint(master).call();
// Create a fix in stable branch.
testRepo.reset(stable);
RevCommit fix = testRepo.commit().parent(stable).message("small fix").add("b.txt", "b").insertChangeId().create();
testRepo.branch("refs/heads/stable").update(fix);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/stable:refs/for/stable/" + name("topic"))).call();
// Merge the fix into master.
testRepo.reset(master);
RevCommit merge = testRepo.commit().parent(master).parent(fix).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/" + name("topic"))).call();
// Submit together.
String fixId = GitUtil.getChangeId(testRepo, fix).get();
String mergeId = GitUtil.getChangeId(testRepo, merge).get();
approve(fixId);
approve(mergeId);
submit(mergeId);
assertMerged(fixId);
assertMerged(mergeId);
testRepo.git().fetch().call();
RevWalk rw = testRepo.getRevWalk();
master = rw.parseCommit(getRemoteHead(project, "master"));
assertThat(rw.isMergedInto(merge, master)).isTrue();
assertThat(rw.isMergedInto(fix, master)).isTrue();
}
use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushSameCommitTwiceUsingMagicBranchBaseOption.
@Test
public void pushSameCommitTwiceUsingMagicBranchBaseOption() throws Exception {
grant(project, "refs/heads/master", Permission.PUSH);
PushOneCommit.Result rBase = pushTo("refs/heads/master");
rBase.assertOkStatus();
gApi.projects().name(project.get()).branch("foo").create(new BranchInput());
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent");
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
PushResult pr = GitUtil.pushHead(testRepo, "refs/for/foo%base=" + rBase.getCommit().name(), false, false);
// BatchUpdate implementations differ in how they hook into progress monitors. We mostly just
// care that there is a new change.
assertThat(pr.getMessages()).containsMatch("changes: new: 1,( refs: 1)? done");
assertTwoChangesWithSameRevision(r);
}
use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.
the class RefAdvertisementIT method setUpChanges.
private void setUpChanges() throws Exception {
gApi.projects().name(project.get()).branch("branch").create(new BranchInput());
// First 2 changes are merged, which means the tags pointing to them are
// visible.
allow(Permission.SUBMIT, admins, "refs/for/refs/heads/*");
PushOneCommit.Result mr = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master%submit");
mr.assertOkStatus();
c1 = mr.getChange();
r1 = changeRefPrefix(c1.getId());
PushOneCommit.Result br = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/branch%submit");
br.assertOkStatus();
c2 = br.getChange();
r2 = changeRefPrefix(c2.getId());
// Second 2 changes are unmerged.
mr = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/master");
mr.assertOkStatus();
c3 = mr.getChange();
r3 = changeRefPrefix(c3.getId());
br = pushFactory.create(db, admin.getIdent(), testRepo).to("refs/for/branch");
br.assertOkStatus();
c4 = br.getChange();
r4 = changeRefPrefix(c4.getId());
try (Repository repo = repoManager.openRepository(project)) {
// master-tag -> master
RefUpdate mtu = repo.updateRef("refs/tags/master-tag");
mtu.setExpectedOldObjectId(ObjectId.zeroId());
mtu.setNewObjectId(repo.exactRef("refs/heads/master").getObjectId());
assertThat(mtu.update()).isEqualTo(RefUpdate.Result.NEW);
// branch-tag -> branch
RefUpdate btu = repo.updateRef("refs/tags/branch-tag");
btu.setExpectedOldObjectId(ObjectId.zeroId());
btu.setNewObjectId(repo.exactRef("refs/heads/branch").getObjectId());
assertThat(btu.update()).isEqualTo(RefUpdate.Result.NEW);
}
}
use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.
the class CreateChangeIT method cherryPickCommitWithoutChangeId.
@Test
public void cherryPickCommitWithoutChangeId() throws Exception {
// This test is a little superfluous, since the current cherry-pick code ignores
// the commit message of the to-be-cherry-picked change, using the one in
// CherryPickInput instead.
CherryPickInput input = new CherryPickInput();
input.destination = "foo";
input.message = "it goes to foo branch";
gApi.projects().name(project.get()).branch(input.destination).create(new BranchInput());
RevCommit revCommit = createNewCommitWithoutChangeId();
ChangeInfo changeInfo = gApi.projects().name(project.get()).commit(revCommit.getName()).cherryPick(input).get();
assertThat(changeInfo.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = changeInfo.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", revCommit.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
assertThat(revInfo).isNotNull();
CommitInfo commitInfo = revInfo.commit;
assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + changeInfo.changeId + "\n");
}
Aggregations