Search in sources :

Example 16 with PushOneCommit

use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithHashtags.

@Test
public void pushForMasterWithHashtags() throws Exception {
    // Hashtags only work when reading from NoteDB is enabled
    assume().that(notesMigration.readChanges()).isTrue();
    // specify a single hashtag as option
    String hashtag1 = "tag1";
    Set<String> expected = ImmutableSet.of(hashtag1);
    PushOneCommit.Result r = pushTo("refs/for/master%hashtag=#" + hashtag1);
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, null);
    Set<String> hashtags = gApi.changes().id(r.getChangeId()).getHashtags();
    assertThat(hashtags).containsExactlyElementsIn(expected);
    // specify a single hashtag as option in new patch set
    String hashtag2 = "tag2";
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent", r.getChangeId());
    r = push.to("refs/for/master/%hashtag=" + hashtag2);
    r.assertOkStatus();
    expected = ImmutableSet.of(hashtag1, hashtag2);
    hashtags = gApi.changes().id(r.getChangeId()).getHashtags();
    assertThat(hashtags).containsExactlyElementsIn(expected);
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with PushOneCommit

use of com.google.gerrit.acceptance.PushOneCommit 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());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 18 with PushOneCommit

use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushChangeBasedOnChangeOfOtherUserWithCreateNewChangeForAllNotInTarget.

@Test
public void pushChangeBasedOnChangeOfOtherUserWithCreateNewChangeForAllNotInTarget() throws Exception {
    enableCreateNewChangeForAllNotInTarget();
    // create a change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "a.txt", "content");
    PushOneCommit.Result r = push.to("refs/for/master");
    r.assertOkStatus();
    RevCommit commitChange1 = r.getCommit();
    // create a second change as user (depends on the change from admin)
    TestRepository<?> userRepo = cloneProject(project, user);
    GitUtil.fetch(userRepo, r.getPatchSet().getRefName() + ":change");
    userRepo.reset("change");
    push = pushFactory.create(db, user.getIdent(), userRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent");
    r = push.to("refs/for/master");
    r.assertOkStatus();
    // assert that no new change was created for the commit of the predecessor change
    assertThat(query(commitChange1.name())).hasSize(1);
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 19 with PushOneCommit

use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushNewPatchsetOverridingStickyLabel.

@Test
public void pushNewPatchsetOverridingStickyLabel() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    LabelType codeReview = Util.codeReview();
    codeReview.setCopyMaxScore(true);
    cfg.getLabelSections().put(codeReview.getName(), codeReview);
    saveProjectConfig(cfg);
    PushOneCommit.Result r = pushTo("refs/for/master%l=Code-Review+2");
    r.assertOkStatus();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent", r.getChangeId());
    r = push.to("refs/for/master%l=Code-Review+1");
    r.assertOkStatus();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) LabelType(com.google.gerrit.common.data.LabelType) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with PushOneCommit

use of com.google.gerrit.acceptance.PushOneCommit 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());
}
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) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)91 Test (org.junit.Test)76 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)72 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)17 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)14 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)13 Project (com.google.gerrit.reviewdb.client.Project)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)7 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)6 ImmutableList (com.google.common.collect.ImmutableList)5 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)5 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)5 IdString (com.google.gerrit.extensions.restapi.IdString)5 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)5 ArrayList (java.util.ArrayList)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)4 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4