NoMergeBaseException.java

  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. package org.eclipse.jgit.errors;

  11. import java.io.IOException;
  12. import java.text.MessageFormat;

  13. import org.eclipse.jgit.internal.JGitText;
  14. import org.eclipse.jgit.merge.RecursiveMerger;

  15. /**
  16.  * Exception thrown if a merge fails because no merge base could be determined.
  17.  *
  18.  * @since 3.0
  19.  */
  20. public class NoMergeBaseException extends IOException {
  21.     private static final long serialVersionUID = 1L;

  22.     private MergeBaseFailureReason reason;

  23.     /**
  24.      * An enum listing the different reason why no merge base could be
  25.      * determined.
  26.      */
  27.     public enum MergeBaseFailureReason {
  28.         /**
  29.          * Multiple merge bases have been found (e.g. the commits to be merged
  30.          * have multiple common predecessors) but the merge strategy doesn't
  31.          * support this (e.g. ResolveMerge)
  32.          */
  33.         MULTIPLE_MERGE_BASES_NOT_SUPPORTED,

  34.         /**
  35.          * The number of merge bases exceeds {@link RecursiveMerger#MAX_BASES}
  36.          */
  37.         TOO_MANY_MERGE_BASES,

  38.         /**
  39.          * In order to find a single merge base it may required to merge
  40.          * together multiple common predecessors. If during these merges
  41.          * conflicts occur the merge fails with this reason
  42.          */
  43.         CONFLICTS_DURING_MERGE_BASE_CALCULATION
  44.     }


  45.     /**
  46.      * Construct a NoMergeBase exception
  47.      *
  48.      * @param reason
  49.      *            the reason why no merge base could be found
  50.      * @param message
  51.      *            a text describing the problem
  52.      */
  53.     public NoMergeBaseException(MergeBaseFailureReason reason, String message) {
  54.         super(MessageFormat.format(JGitText.get().noMergeBase,
  55.                 reason.toString(), message));
  56.         this.reason = reason;
  57.     }

  58.     /**
  59.      * Construct a NoMergeBase exception
  60.      *
  61.      * @param reason
  62.      *            the reason why no merge base could be found
  63.      * @param message
  64.      *            a text describing the problem
  65.      * @param why
  66.      *            an exception causing this error
  67.      */
  68.     public NoMergeBaseException(MergeBaseFailureReason reason, String message,
  69.             Throwable why) {
  70.         super(MessageFormat.format(JGitText.get().noMergeBase,
  71.                 reason.toString(), message));
  72.         this.reason = reason;
  73.         initCause(why);
  74.     }

  75.     /**
  76.      * Get the reason why no merge base could be found
  77.      *
  78.      * @return the reason why no merge base could be found
  79.      */
  80.     public MergeBaseFailureReason getReason() {
  81.         return reason;
  82.     }
  83. }