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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Copyright (C) 2010, 2013, 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.List;
  45. import java.util.Map;
  46. import org.eclipse.jgit.merge.ResolveMerger;
  47. import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
  48. import org.eclipse.jgit.revwalk.RevCommit;
  49. /**
  50. * The result of a {@link RebaseCommand} execution
  51. */
  52. public class RebaseResult {
  53. /**
  54. * The overall status
  55. */
  56. public enum Status {
  57. /**
  58. * Rebase was successful, HEAD points to the new commit
  59. */
  60. OK {
  61. @Override
  62. public boolean isSuccessful() {
  63. return true;
  64. }
  65. },
  66. /**
  67. * Aborted; the original HEAD was restored
  68. */
  69. ABORTED {
  70. @Override
  71. public boolean isSuccessful() {
  72. return false;
  73. }
  74. },
  75. /**
  76. * Stopped due to a conflict; must either abort or resolve or skip
  77. */
  78. STOPPED {
  79. @Override
  80. public boolean isSuccessful() {
  81. return false;
  82. }
  83. },
  84. /**
  85. * Stopped for editing in the context of an interactive rebase
  86. *
  87. * @since 3.2
  88. */
  89. EDIT {
  90. @Override
  91. public boolean isSuccessful() {
  92. return false;
  93. }
  94. },
  95. /**
  96. * Failed; the original HEAD was restored
  97. */
  98. FAILED {
  99. @Override
  100. public boolean isSuccessful() {
  101. return false;
  102. }
  103. },
  104. /**
  105. * Conflicts: checkout of target HEAD failed
  106. */
  107. CONFLICTS {
  108. @Override
  109. public boolean isSuccessful() {
  110. return false;
  111. }
  112. },
  113. /**
  114. * Already up-to-date
  115. */
  116. UP_TO_DATE {
  117. @Override
  118. public boolean isSuccessful() {
  119. return true;
  120. }
  121. },
  122. /**
  123. * Fast-forward, HEAD points to the new commit
  124. */
  125. FAST_FORWARD {
  126. @Override
  127. public boolean isSuccessful() {
  128. return true;
  129. }
  130. },
  131. /**
  132. * Continue with nothing left to commit (possibly want skip).
  133. *
  134. * @since 2.0
  135. */
  136. NOTHING_TO_COMMIT {
  137. @Override
  138. public boolean isSuccessful() {
  139. return false;
  140. }
  141. },
  142. /**
  143. * Interactive rebase has been prepared
  144. * @since 3.2
  145. */
  146. INTERACTIVE_PREPARED {
  147. @Override
  148. public boolean isSuccessful() {
  149. return false;
  150. }
  151. };
  152. /**
  153. * @return whether the status indicates a successful result
  154. */
  155. public abstract boolean isSuccessful();
  156. }
  157. static final RebaseResult OK_RESULT = new RebaseResult(Status.OK);
  158. static final RebaseResult ABORTED_RESULT = new RebaseResult(Status.ABORTED);
  159. static final RebaseResult UP_TO_DATE_RESULT = new RebaseResult(
  160. Status.UP_TO_DATE);
  161. static final RebaseResult FAST_FORWARD_RESULT = new RebaseResult(
  162. Status.FAST_FORWARD);
  163. static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult(
  164. Status.NOTHING_TO_COMMIT);
  165. static final RebaseResult INTERACTIVE_PREPARED_RESULT = new RebaseResult(
  166. Status.INTERACTIVE_PREPARED);
  167. private final Status status;
  168. private final RevCommit currentCommit;
  169. private Map<String, MergeFailureReason> failingPaths;
  170. private List<String> conflicts;
  171. private RebaseResult(Status status) {
  172. this.status = status;
  173. currentCommit = null;
  174. }
  175. private RebaseResult(Status status, RevCommit commit) {
  176. this.status = status;
  177. currentCommit = commit;
  178. }
  179. /**
  180. * Create <code>RebaseResult</code>
  181. *
  182. * @param status
  183. * @param commit
  184. * current commit
  185. * @return the RebaseResult
  186. */
  187. static RebaseResult result(RebaseResult.Status status,
  188. RevCommit commit) {
  189. return new RebaseResult(status, commit);
  190. }
  191. /**
  192. * Create <code>RebaseResult</code> with status {@link Status#FAILED}
  193. *
  194. * @param failingPaths
  195. * list of paths causing this rebase to fail
  196. * @return the RebaseResult
  197. */
  198. static RebaseResult failed(
  199. Map<String, MergeFailureReason> failingPaths) {
  200. RebaseResult result = new RebaseResult(Status.FAILED);
  201. result.failingPaths = failingPaths;
  202. return result;
  203. }
  204. /**
  205. * Create <code>RebaseResult</code> with status {@link Status#CONFLICTS}
  206. *
  207. * @param conflicts
  208. * the list of conflicting paths
  209. * @return the RebaseResult
  210. */
  211. static RebaseResult conflicts(List<String> conflicts) {
  212. RebaseResult result = new RebaseResult(Status.CONFLICTS);
  213. result.conflicts = conflicts;
  214. return result;
  215. }
  216. /**
  217. * @return the overall status
  218. */
  219. public Status getStatus() {
  220. return status;
  221. }
  222. /**
  223. * @return the current commit if status is {@link Status#STOPPED}, otherwise
  224. * <code>null</code>
  225. */
  226. public RevCommit getCurrentCommit() {
  227. return currentCommit;
  228. }
  229. /**
  230. * @return the list of paths causing this rebase to fail (see
  231. * {@link ResolveMerger#getFailingPaths()} for details) if status is
  232. * {@link Status#FAILED}, otherwise <code>null</code>
  233. */
  234. public Map<String, MergeFailureReason> getFailingPaths() {
  235. return failingPaths;
  236. }
  237. /**
  238. * @return the list of conflicts if status is {@link Status#CONFLICTS}
  239. */
  240. public List<String> getConflicts() {
  241. return conflicts;
  242. }
  243. }