Cherry-pick: Differentiate between conflicts and already merged errors

When cherry-pick operation fails with "Cherry pick failed" error, there
is no way to know the reason for the failure: merge conflict or the
commit is already on the target branch.  Differentiate between these
failures and report the proper result to the client.

Change-Id: If1139e3c13623fb98a9584e4e399cfdf45fd3613
This commit is contained in:
David Ostrovsky
2014-07-19 09:43:07 +02:00
parent 9d9e54df09
commit 6d83eba0bf
7 changed files with 128 additions and 23 deletions

View File

@@ -26,7 +26,9 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.MergeException;
import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.util.TimeUtil;
@@ -84,15 +86,16 @@ public class CherryPick extends SubmitStrategy {
// taking the delta relative to that one parent and redoing
// that on the current merge tip.
//
mergeTip = writeCherryPickCommit(mergeTip, n);
if (mergeTip != null) {
try {
mergeTip = writeCherryPickCommit(mergeTip, n);
newCommits.put(mergeTip.getPatchsetId().getParentKey(), mergeTip);
} else {
} catch (MergeConflictException mce) {
n.setStatusCode(CommitMergeStatus.PATH_CONFLICT);
mergeTip = null;
} catch (MergeIdenticalTreeException mie) {
n.setStatusCode(CommitMergeStatus.ALREADY_MERGED);
mergeTip = null;
}
} else {
// There are multiple parents, so this is a merge commit. We
// don't want to cherry-pick the merge as clients can't easily
@@ -131,7 +134,8 @@ public class CherryPick extends SubmitStrategy {
private CodeReviewCommit writeCherryPickCommit(CodeReviewCommit mergeTip,
CodeReviewCommit n) throws IOException, OrmException,
NoSuchChangeException {
NoSuchChangeException, MergeConflictException,
MergeIdenticalTreeException {
args.rw.parseBody(n);
@@ -156,10 +160,6 @@ public class CherryPick extends SubmitStrategy {
args.inserter, mergeTip, n, cherryPickCommitterIdent,
cherryPickCmtMsg, args.rw);
if (newCommit == null) {
return null;
}
PatchSet.Id id =
ChangeUtil.nextPatchSetId(args.repo, n.change().currentPatchSetId());
final PatchSet ps = new PatchSet(id);