Search in sources :

Example 21 with BranchInput

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

the class AbstractPushForReview method createNewChangeForAllNotInTarget.

@Test
public void createNewChangeForAllNotInTarget() throws Exception {
    enableCreateNewChangeForAllNotInTarget();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "a.txt", "content");
    PushOneCommit.Result r = push.to("refs/for/master");
    r.assertOkStatus();
    push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent");
    r = push.to("refs/for/master");
    r.assertOkStatus();
    gApi.projects().name(project.get()).branch("otherBranch").create(new BranchInput());
    PushOneCommit.Result r2 = push.to("refs/for/otherBranch");
    r2.assertOkStatus();
    assertTwoChangesWithSameRevision(r);
}
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 22 with BranchInput

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

the class AbstractSubmit method submitWholeTopicMultipleBranchesOnSameProject.

@Test
public void submitWholeTopicMultipleBranchesOnSameProject() throws Exception {
    assume().that(isSubmitWholeTopicEnabled()).isTrue();
    String topic = "test-topic";
    // Create test project
    String projectName = "project-a";
    TestRepository<?> repoA = createProjectWithPush(projectName, null, getSubmitType());
    RevCommit initialHead = getRemoteHead(new Project.NameKey(name(projectName)), "master");
    // Create the dev branch on the test project
    BranchInput in = new BranchInput();
    in.revision = initialHead.name();
    gApi.projects().name(name(projectName)).branch("dev").create(in);
    // Create changes on master
    PushOneCommit.Result change1 = createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
    PushOneCommit.Result change2 = createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
    // Create  changes on dev
    repoA.reset(initialHead);
    PushOneCommit.Result change3 = createChange(repoA, "dev", "Change 3", "a.txt", "content", topic);
    PushOneCommit.Result change4 = createChange(repoA, "dev", "Change 4", "b.txt", "content", topic);
    approve(change1.getChangeId());
    approve(change2.getChangeId());
    approve(change3.getChangeId());
    approve(change4.getChangeId());
    submit(change4.getChangeId());
    String expectedTopic = name(topic);
    change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
    change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
    change3.assertChange(Change.Status.MERGED, expectedTopic, admin);
    change4.assertChange(Change.Status.MERGED, expectedTopic, admin);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with BranchInput

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

the class MoveChangeIT method moveChangeToBranchThatContainsCurrentCommit.

@Test
public void moveChangeToBranchThatContainsCurrentCommit() throws Exception {
    // Move change to a branch for which current PS revision is reachable from
    // tip
    // Create a change
    PushOneCommit.Result r = createChange();
    int changeNum = r.getChange().change().getChangeId();
    // Create a branch with that same commit
    Branch.NameKey newBranch = new Branch.NameKey(r.getChange().change().getProject(), "moveTest");
    BranchInput bi = new BranchInput();
    bi.revision = r.getCommit().name();
    gApi.projects().name(newBranch.getParentKey().get()).branch(newBranch.get()).create(bi);
    // Try to move the change to the branch with the same commit
    exception.expect(ResourceConflictException.class);
    exception.expectMessage("Current patchset revision is reachable from tip of " + newBranch.get());
    move(changeNum, newBranch.get());
}
Also used : Branch(com.google.gerrit.reviewdb.client.Branch) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 24 with BranchInput

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

the class SubmitByMergeIfNecessaryIT method openChangeForTargetBranchPreventsMerge.

@Test
public void openChangeForTargetBranchPreventsMerge() throws Exception {
    gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
    // Propose a change for master, but leave it open for master!
    PushOneCommit change = pushFactory.create(db, user.getIdent(), testRepo, "small fix", "a.txt", "2");
    PushOneCommit.Result change2result = change.to("refs/for/master");
    // Now cherry pick to stable
    CherryPickInput in = new CherryPickInput();
    in.destination = "stable";
    in.message = "it goes to stable branch";
    ChangeApi orig = gApi.changes().id(change2result.getChangeId());
    ChangeApi cherry = orig.current().cherryPick(in);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
    // Create a commit locally
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/stable")).call();
    PushOneCommit.Result change3 = createChange(testRepo, "stable", "test", "a.txt", "3", "");
    submitWithConflict(change3.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change3.getPatchSetId().getParentKey().get() + ": depends on change that was not submitted");
    assertRefUpdatedEvents();
    assertChangeMergedEvents();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test)

Example 25 with BranchInput

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

the class SubmitByMergeIfNecessaryIT method submitWithOpenAncestorsOnOtherBranch.

@Test
public void submitWithOpenAncestorsOnOtherBranch() throws Exception {
    RevCommit initialHead = getRemoteHead();
    PushOneCommit.Result change1 = createChange(testRepo, "master", "base commit", "a.txt", "1", "");
    submit(change1.getChangeId());
    RevCommit headAfterFirstSubmit = getRemoteHead();
    gApi.projects().name(project.get()).branch("branch").create(new BranchInput());
    PushOneCommit.Result change2 = createChange(testRepo, "master", "We want to commit this to master first", "a.txt", "2", "");
    approve(change2.getChangeId());
    RevCommit tip1 = getRemoteLog(project, "master").get(0);
    assertThat(tip1.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    RevCommit tip2 = getRemoteLog(project, "branch").get(0);
    assertThat(tip2.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    PushOneCommit.Result change3a = createChange(testRepo, "branch", "This commit is based on change2 pending for master, " + "but is targeted itself at branch, which doesn't include it.", "a.txt", "3", "a-topic-here");
    Project.NameKey p3 = createProject("project-related-to-change3");
    TestRepository<?> repo3 = cloneProject(p3);
    RevCommit repo3Head = getRemoteHead(p3, "master");
    PushOneCommit.Result change3b = createChange(repo3, "master", "some accompanying changes for change3a in another repo tied together via topic", "a.txt", "1", "a-topic-here");
    approve(change3b.getChangeId());
    String cnt = isSubmitWholeTopicEnabled() ? "2 changes" : "1 change";
    submitWithConflict(change3a.getChangeId(), "Failed to submit " + cnt + " due to the following problems:\n" + "Change " + change3a.getChange().getId() + ": depends on change that" + " was not submitted");
    RevCommit tipbranch = getRemoteLog(project, "branch").get(0);
    assertThat(tipbranch.getShortMessage()).isEqualTo(change1.getCommit().getShortMessage());
    RevCommit tipmaster = getRemoteLog(p3, "master").get(0);
    assertThat(tipmaster.getShortMessage()).isEqualTo(repo3Head.getShortMessage());
    assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
    assertChangeMergedEvents(change1.getChangeId(), headAfterFirstSubmit.name());
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) 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