Catch NoMergeBaseException when no merge base was found
Matching on the IOException string broke in upstream JGit. Fortunately, upstream now has a new exception type that gets thrown, along with a reason enum, so our error handling can be more future-proof. Change-Id: Icd6156353fa700d4598b601ed4c1cd072de5031c
This commit is contained in:
@@ -45,9 +45,9 @@ enum CommitMergeStatus {
|
||||
NO_SUBMIT_TYPE(""),
|
||||
|
||||
/** */
|
||||
CRISS_CROSS_MERGE("The change requires a recursive merge to resolve.\n"
|
||||
+ "\n"
|
||||
+ "Please merge (or rebase) the change locally and upload the resolution for review."),
|
||||
MANUAL_RECURSIVE_MERGE("The change requires a local merge to resolve.\n"
|
||||
+ "\n"
|
||||
+ "Please merge (or rebase) the change locally and upload the resolution for review."),
|
||||
|
||||
/** */
|
||||
CANNOT_CHERRY_PICK_ROOT("Cannot cherry-pick an initial commit onto an existing branch.\n"
|
||||
@@ -92,4 +92,4 @@ enum CommitMergeStatus {
|
||||
public String getMessage(){
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -750,7 +750,7 @@ public class MergeOp {
|
||||
break;
|
||||
|
||||
case PATH_CONFLICT:
|
||||
case CRISS_CROSS_MERGE:
|
||||
case MANUAL_RECURSIVE_MERGE:
|
||||
case CANNOT_CHERRY_PICK_ROOT:
|
||||
case NOT_FAST_FORWARD:
|
||||
case INVALID_PROJECT_CONFIGURATION:
|
||||
|
@@ -28,6 +28,8 @@ import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.errors.NoMergeBaseException;
|
||||
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
|
||||
import org.eclipse.jgit.lib.AnyObjectId;
|
||||
import org.eclipse.jgit.lib.CommitBuilder;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
@@ -370,10 +372,9 @@ public class MergeUtil {
|
||||
newThreeWayMerger(repo, createDryRunInserter(), useContentMerge);
|
||||
try {
|
||||
return m.merge(new AnyObjectId[] {mergeTip, toMerge});
|
||||
} catch (NoMergeBaseException e) {
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().startsWith("Multiple merge bases for")) {
|
||||
return false;
|
||||
}
|
||||
throw new MergeException("Cannot merge " + toMerge.name(), e);
|
||||
}
|
||||
}
|
||||
@@ -488,21 +489,31 @@ public class MergeUtil {
|
||||
} else {
|
||||
failed(rw, canMergeFlag, mergeTip, n, CommitMergeStatus.PATH_CONFLICT);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (e.getMessage().startsWith("Multiple merge bases for")) {
|
||||
try {
|
||||
failed(rw, canMergeFlag, mergeTip, n,
|
||||
CommitMergeStatus.CRISS_CROSS_MERGE);
|
||||
} catch (IOException e2) {
|
||||
throw new MergeException("Cannot merge " + n.name(), e);
|
||||
}
|
||||
} else {
|
||||
} catch (NoMergeBaseException e) {
|
||||
try {
|
||||
failed(rw, canMergeFlag, mergeTip, n,
|
||||
getCommitMergeStatus(e.getReason()));
|
||||
} catch (IOException e2) {
|
||||
throw new MergeException("Cannot merge " + n.name(), e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new MergeException("Cannot merge " + n.name(), e);
|
||||
}
|
||||
return mergeTip;
|
||||
}
|
||||
|
||||
private static CommitMergeStatus getCommitMergeStatus(
|
||||
MergeBaseFailureReason reason) {
|
||||
switch (reason) {
|
||||
case MULTIPLE_MERGE_BASES_NOT_SUPPORTED:
|
||||
case TOO_MANY_MERGE_BASES:
|
||||
default:
|
||||
return CommitMergeStatus.MANUAL_RECURSIVE_MERGE;
|
||||
case CONFLICTS_DURING_MERGE_BASE_CALCULATION:
|
||||
return CommitMergeStatus.PATH_CONFLICT;
|
||||
}
|
||||
}
|
||||
|
||||
private static CodeReviewCommit failed(final RevWalk rw,
|
||||
final RevFlag canMergeFlag, final CodeReviewCommit mergeTip,
|
||||
final CodeReviewCommit n, final CommitMergeStatus failure)
|
||||
|
Reference in New Issue
Block a user