You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RebaseResult.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.api;
  44. import java.util.Map;
  45. import org.eclipse.jgit.merge.ResolveMerger;
  46. import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
  47. import org.eclipse.jgit.revwalk.RevCommit;
  48. /**
  49. * The result of a {@link RebaseCommand} execution
  50. */
  51. public class RebaseResult {
  52. /**
  53. * The overall status
  54. */
  55. public enum Status {
  56. /**
  57. * Rebase was successful, HEAD points to the new commit
  58. */
  59. OK {
  60. @Override
  61. public boolean isSuccessful() {
  62. return true;
  63. }
  64. },
  65. /**
  66. * Aborted; the original HEAD was restored
  67. */
  68. ABORTED {
  69. @Override
  70. public boolean isSuccessful() {
  71. return false;
  72. }
  73. },
  74. /**
  75. * Stopped due to a conflict; must either abort or resolve or skip
  76. */
  77. STOPPED {
  78. @Override
  79. public boolean isSuccessful() {
  80. return false;
  81. }
  82. },
  83. /**
  84. * Failed; the original HEAD was restored
  85. */
  86. FAILED {
  87. @Override
  88. public boolean isSuccessful() {
  89. return false;
  90. }
  91. },
  92. /**
  93. * Already up-to-date
  94. */
  95. UP_TO_DATE {
  96. @Override
  97. public boolean isSuccessful() {
  98. return true;
  99. }
  100. },
  101. /**
  102. * Fast-forward, HEAD points to the new commit
  103. */
  104. FAST_FORWARD {
  105. @Override
  106. public boolean isSuccessful() {
  107. return true;
  108. }
  109. },
  110. /**
  111. * Continue with nothing left to commit (possibly want skip).
  112. */
  113. NOTHING_TO_COMMIT {
  114. @Override
  115. public boolean isSuccessful() {
  116. return false;
  117. }
  118. };
  119. /**
  120. * @return whether the status indicates a successful result
  121. */
  122. public abstract boolean isSuccessful();
  123. }
  124. static final RebaseResult OK_RESULT = new RebaseResult(Status.OK);
  125. static final RebaseResult ABORTED_RESULT = new RebaseResult(Status.ABORTED);
  126. static final RebaseResult UP_TO_DATE_RESULT = new RebaseResult(
  127. Status.UP_TO_DATE);
  128. static final RebaseResult FAST_FORWARD_RESULT = new RebaseResult(
  129. Status.FAST_FORWARD);
  130. static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult(
  131. Status.NOTHING_TO_COMMIT);
  132. private final Status status;
  133. private final RevCommit currentCommit;
  134. private Map<String, MergeFailureReason> failingPaths;
  135. private RebaseResult(Status status) {
  136. this.status = status;
  137. currentCommit = null;
  138. }
  139. /**
  140. * Create <code>RebaseResult</code> with status {@link Status#STOPPED}
  141. *
  142. * @param commit
  143. * current commit
  144. */
  145. RebaseResult(RevCommit commit) {
  146. status = Status.STOPPED;
  147. currentCommit = commit;
  148. }
  149. /**
  150. * Create <code>RebaseResult</code> with status {@link Status#FAILED}
  151. *
  152. * @param failingPaths
  153. * list of paths causing this rebase to fail
  154. */
  155. RebaseResult(Map<String, MergeFailureReason> failingPaths) {
  156. status = Status.FAILED;
  157. currentCommit = null;
  158. this.failingPaths = failingPaths;
  159. }
  160. /**
  161. * @return the overall status
  162. */
  163. public Status getStatus() {
  164. return status;
  165. }
  166. /**
  167. * @return the current commit if status is {@link Status#STOPPED}, otherwise
  168. * <code>null</code>
  169. */
  170. public RevCommit getCurrentCommit() {
  171. return currentCommit;
  172. }
  173. /**
  174. * @return the list of paths causing this rebase to fail (see
  175. * {@link ResolveMerger#getFailingPaths()} for details) if status is
  176. * {@link Status#FAILED}, otherwise <code>null</code>
  177. */
  178. public Map<String, MergeFailureReason> getFailingPaths() {
  179. return failingPaths;
  180. }
  181. }