Search in sources :

Example 11 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 12 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class AgreementsIT method cherrypickChangeWithoutCLA.

@Test
public void cherrypickChangeWithoutCLA() throws Exception {
    assume().that(isContributorAgreementsEnabled()).isTrue();
    // Create a new branch
    setApiUser(admin);
    BranchInfo dest = gApi.projects().name(project.get()).branch("cherry-pick-to").create(new BranchInput()).get();
    // Create a change succeeds when agreement is not required
    setUseContributorAgreements(InheritableBoolean.FALSE);
    ChangeInfo change = gApi.changes().create(newChangeInput()).get();
    // Approve and submit it
    gApi.changes().id(change.changeId).current().review(ReviewInput.approve());
    gApi.changes().id(change.changeId).current().submit(new SubmitInput());
    // Cherry-pick is not allowed when CLA is required but not signed
    setApiUser(user);
    setUseContributorAgreements(InheritableBoolean.TRUE);
    CherryPickInput in = new CherryPickInput();
    in.destination = dest.ref;
    in.message = change.subject;
    exception.expect(AuthException.class);
    exception.expectMessage("A Contributor Agreement must be completed");
    gApi.changes().id(change.changeId).current().cherryPick(in);
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) BranchInfo(com.google.gerrit.extensions.api.projects.BranchInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 13 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class ChangeIT method getAmbiguous.

@Test
public void getAmbiguous() throws Exception {
    PushOneCommit.Result r1 = createChange();
    String changeId = r1.getChangeId();
    gApi.changes().id(changeId).get();
    BranchInput b = new BranchInput();
    b.revision = repo().exactRef("HEAD").getObjectId().name();
    gApi.projects().name(project.get()).branch("other").create(b);
    PushOneCommit push2 = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT, changeId);
    PushOneCommit.Result r2 = push2.to("refs/for/other");
    assertThat(r2.getChangeId()).isEqualTo(changeId);
    exception.expect(ResourceNotFoundException.class);
    exception.expectMessage("Multiple changes found for " + changeId);
    gApi.changes().id(changeId).get();
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class SubmitTypeRuleIT method setUp.

@Before
public void setUp() throws Exception {
    fileCounter = new AtomicInteger();
    gApi.projects().name(project.get()).branch("test").create(new BranchInput());
    testChangeId = createChange("test", "test change").getChange().getId();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Before(org.junit.Before)

Example 15 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class ProjectIT method createBranch.

@Test
public void createBranch() throws Exception {
    allow(Permission.READ, ANONYMOUS_USERS, "refs/*");
    gApi.projects().name(project.get()).branch("foo").create(new BranchInput());
}
Also used : BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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