1 /* 2 * Copyright (C) 2013, Christian Halstrick <christian.halstrick@sap.com> and others 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the Eclipse Distribution License v. 1.0 which is available at 6 * https://www.eclipse.org/org/documents/edl-v10.php. 7 * 8 * SPDX-License-Identifier: BSD-3-Clause 9 */ 10 11 package org.eclipse.jgit.errors; 12 13 import java.io.IOException; 14 import java.text.MessageFormat; 15 16 import org.eclipse.jgit.internal.JGitText; 17 import org.eclipse.jgit.merge.RecursiveMerger; 18 19 /** 20 * Exception thrown if a merge fails because no merge base could be determined. 21 * 22 * @since 3.0 23 */ 24 public class NoMergeBaseException extends IOException { 25 private static final long serialVersionUID = 1L; 26 27 private MergeBaseFailureReason reason; 28 29 /** 30 * An enum listing the different reason why no merge base could be 31 * determined. 32 */ 33 public enum MergeBaseFailureReason { 34 /** 35 * Multiple merge bases have been found (e.g. the commits to be merged 36 * have multiple common predecessors) but the merge strategy doesn't 37 * support this (e.g. ResolveMerge) 38 */ 39 MULTIPLE_MERGE_BASES_NOT_SUPPORTED, 40 41 /** 42 * The number of merge bases exceeds {@link RecursiveMerger#MAX_BASES} 43 */ 44 TOO_MANY_MERGE_BASES, 45 46 /** 47 * In order to find a single merge base it may required to merge 48 * together multiple common predecessors. If during these merges 49 * conflicts occur the merge fails with this reason 50 */ 51 CONFLICTS_DURING_MERGE_BASE_CALCULATION 52 } 53 54 55 /** 56 * Construct a NoMergeBase exception 57 * 58 * @param reason 59 * the reason why no merge base could be found 60 * @param message 61 * a text describing the problem 62 */ 63 public NoMergeBaseException(MergeBaseFailureReason reason, String message) { 64 super(MessageFormat.format(JGitText.get().noMergeBase, 65 reason.toString(), message)); 66 this.reason = reason; 67 } 68 69 /** 70 * Construct a NoMergeBase exception 71 * 72 * @param reason 73 * the reason why no merge base could be found 74 * @param message 75 * a text describing the problem 76 * @param why 77 * an exception causing this error 78 */ 79 public NoMergeBaseException(MergeBaseFailureReason reason, String message, 80 Throwable why) { 81 super(MessageFormat.format(JGitText.get().noMergeBase, 82 reason.toString(), message)); 83 this.reason = reason; 84 initCause(why); 85 } 86 87 /** 88 * Get the reason why no merge base could be found 89 * 90 * @return the reason why no merge base could be found 91 */ 92 public MergeBaseFailureReason getReason() { 93 return reason; 94 } 95 }