| // Copyright (C) 2013 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package com.google.gerrit.acceptance.rest.change; |
| |
| import static com.google.common.truth.Truth.assertThat; |
| |
| import com.google.gerrit.acceptance.PushOneCommit; |
| import com.google.gerrit.extensions.client.SubmitType; |
| |
| import org.eclipse.jgit.revwalk.RevCommit; |
| import org.junit.Test; |
| |
| import java.util.List; |
| |
| public class SubmitByMergeAlwaysIT extends AbstractSubmitByMerge { |
| |
| @Override |
| protected SubmitType getSubmitType() { |
| return SubmitType.MERGE_ALWAYS; |
| } |
| |
| @Test |
| public void submitWithMergeIfFastForwardPossible() throws Exception { |
| RevCommit oldHead = getRemoteHead(); |
| PushOneCommit.Result change = createChange(); |
| submit(change.getChangeId()); |
| RevCommit head = getRemoteHead(); |
| assertThat(head.getParentCount()).isEqualTo(2); |
| assertThat(head.getParent(0)).isEqualTo(oldHead); |
| assertThat(head.getParent(1)).isEqualTo(change.getCommitId()); |
| assertSubmitter(change.getChangeId(), 1); |
| assertPersonEquals(admin.getIdent(), head.getAuthorIdent()); |
| assertPersonEquals(serverIdent.get(), head.getCommitterIdent()); |
| } |
| |
| @Test |
| public void submitMultipleChanges() throws Exception { |
| RevCommit initialHead = getRemoteHead(); |
| |
| testRepo.reset(initialHead); |
| PushOneCommit.Result change2 = createChange("Change 2", "b", "b"); |
| |
| testRepo.reset(initialHead); |
| PushOneCommit.Result change3 = createChange("Change 3", "c", "c"); |
| |
| testRepo.reset(initialHead); |
| PushOneCommit.Result change4 = createChange("Change 4", "d", "d"); |
| |
| approve(change2.getChangeId()); |
| approve(change3.getChangeId()); |
| submit(change4.getChangeId()); |
| |
| List<RevCommit> log = getRemoteLog(); |
| RevCommit tip = log.get(0); |
| assertThat(tip.getParent(1).getShortMessage()).isEqualTo( |
| change4.getCommit().getShortMessage()); |
| assertThat(tip.getParent(0).getShortMessage()).isEqualTo( |
| initialHead.getShortMessage()); |
| assertThat(tip.getParent(0).getId()).isEqualTo(initialHead.getId()); |
| |
| assertPersonEquals(admin.getIdent(), tip.getAuthorIdent()); |
| assertPersonEquals(serverIdent.get(), tip.getCommitterIdent()); |
| |
| assertNew(change2.getChangeId()); |
| assertNew(change3.getChangeId()); |
| } |
| } |