Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.submit; 16 : 17 : import static com.google.gerrit.server.submit.CommitMergeStatus.EMPTY_COMMIT; 18 : 19 : import com.google.gerrit.entities.BooleanProjectConfig; 20 : import com.google.gerrit.server.git.CodeReviewCommit; 21 : import com.google.gerrit.server.update.RepoContext; 22 : import java.io.IOException; 23 : import org.eclipse.jgit.lib.PersonIdent; 24 : 25 : class MergeOneOp extends SubmitStrategyOp { 26 : MergeOneOp(SubmitStrategy.Arguments args, CodeReviewCommit toMerge) { 27 18 : super(args, toMerge); 28 18 : } 29 : 30 : @Override 31 : public void updateRepoImpl(RepoContext ctx) throws IntegrationConflictException, IOException { 32 18 : PersonIdent caller = ctx.getIdentifiedUser().newCommitterIdent(args.serverIdent); 33 18 : if (args.mergeTip.getCurrentTip() == null) { 34 0 : throw new IllegalStateException( 35 : "cannot merge commit " 36 0 : + toMerge.name() 37 : + " onto a null tip; expected at least one fast-forward prior to" 38 : + " this operation"); 39 : } 40 18 : CodeReviewCommit merged = 41 18 : args.mergeUtil.mergeOneCommit( 42 : caller, 43 : args.serverIdent, 44 : args.rw, 45 18 : ctx.getInserter(), 46 18 : ctx.getRepoView().getConfig(), 47 : args.destBranch, 48 18 : args.mergeTip.getCurrentTip(), 49 : toMerge); 50 18 : if (args.project.is(BooleanProjectConfig.REJECT_EMPTY_COMMIT) 51 2 : && merged.getTree().equals(merged.getParent(0).getTree())) { 52 2 : toMerge.setStatusCode(EMPTY_COMMIT); 53 2 : return; 54 : } 55 18 : args.mergeTip.moveTipTo(amendGitlink(merged), toMerge); 56 18 : } 57 : }