Search in sources :

Example 6 with BranchInput

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);
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput)

Example 7 with BranchInput

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();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with BranchInput

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);
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushResult(org.eclipse.jgit.transport.PushResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with BranchInput

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);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 10 with BranchInput

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");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)30 Test (org.junit.Test)21 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)17 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)4 Branch (com.google.gerrit.reviewdb.client.Branch)4 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)3 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)3 RefSpec (org.eclipse.jgit.transport.RefSpec)3 Before (org.junit.Before)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 Project (com.google.gerrit.reviewdb.client.Project)2 RefUpdate (org.eclipse.jgit.lib.RefUpdate)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)1