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:
Dave Borowitz
2013-03-12 16:01:38 -07:00
parent 81968b49f9
commit eddd3197a9
3 changed files with 28 additions and 17 deletions

View File

@@ -45,9 +45,9 @@ enum CommitMergeStatus {
NO_SUBMIT_TYPE(""), NO_SUBMIT_TYPE(""),
/** */ /** */
CRISS_CROSS_MERGE("The change requires a recursive merge to resolve.\n" MANUAL_RECURSIVE_MERGE("The change requires a local merge to resolve.\n"
+ "\n" + "\n"
+ "Please merge (or rebase) the change locally and upload the resolution for review."), + "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" CANNOT_CHERRY_PICK_ROOT("Cannot cherry-pick an initial commit onto an existing branch.\n"
@@ -92,4 +92,4 @@ enum CommitMergeStatus {
public String getMessage(){ public String getMessage(){
return message; return message;
} }
} }

View File

@@ -750,7 +750,7 @@ public class MergeOp {
break; break;
case PATH_CONFLICT: case PATH_CONFLICT:
case CRISS_CROSS_MERGE: case MANUAL_RECURSIVE_MERGE:
case CANNOT_CHERRY_PICK_ROOT: case CANNOT_CHERRY_PICK_ROOT:
case NOT_FAST_FORWARD: case NOT_FAST_FORWARD:
case INVALID_PROJECT_CONFIGURATION: case INVALID_PROJECT_CONFIGURATION:

View File

@@ -28,6 +28,8 @@ import com.google.inject.Provider;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException; 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.AnyObjectId;
import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
@@ -370,10 +372,9 @@ public class MergeUtil {
newThreeWayMerger(repo, createDryRunInserter(), useContentMerge); newThreeWayMerger(repo, createDryRunInserter(), useContentMerge);
try { try {
return m.merge(new AnyObjectId[] {mergeTip, toMerge}); return m.merge(new AnyObjectId[] {mergeTip, toMerge});
} catch (NoMergeBaseException e) {
return false;
} catch (IOException e) { } catch (IOException e) {
if (e.getMessage().startsWith("Multiple merge bases for")) {
return false;
}
throw new MergeException("Cannot merge " + toMerge.name(), e); throw new MergeException("Cannot merge " + toMerge.name(), e);
} }
} }
@@ -488,21 +489,31 @@ public class MergeUtil {
} else { } else {
failed(rw, canMergeFlag, mergeTip, n, CommitMergeStatus.PATH_CONFLICT); failed(rw, canMergeFlag, mergeTip, n, CommitMergeStatus.PATH_CONFLICT);
} }
} catch (IOException e) { } catch (NoMergeBaseException e) {
if (e.getMessage().startsWith("Multiple merge bases for")) { try {
try { failed(rw, canMergeFlag, mergeTip, n,
failed(rw, canMergeFlag, mergeTip, n, getCommitMergeStatus(e.getReason()));
CommitMergeStatus.CRISS_CROSS_MERGE); } catch (IOException e2) {
} catch (IOException e2) {
throw new MergeException("Cannot merge " + n.name(), e);
}
} else {
throw new MergeException("Cannot merge " + n.name(), e); throw new MergeException("Cannot merge " + n.name(), e);
} }
} catch (IOException e) {
throw new MergeException("Cannot merge " + n.name(), e);
} }
return mergeTip; 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, private static CodeReviewCommit failed(final RevWalk rw,
final RevFlag canMergeFlag, final CodeReviewCommit mergeTip, final RevFlag canMergeFlag, final CodeReviewCommit mergeTip,
final CodeReviewCommit n, final CommitMergeStatus failure) final CodeReviewCommit n, final CommitMergeStatus failure)