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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. * The repository contains uncommitted changes and the rebase is not a
  106. * fast-forward
  107. *
  108. * @since 3.2
  109. */
  110. UNCOMMITTED_CHANGES {
  111. @Override
  112. public boolean isSuccessful() {
  113. return false;
  114. }
  115. },
  116. /**
  117. * Conflicts: checkout of target HEAD failed
  118. */
  119. CONFLICTS {
  120. @Override
  121. public boolean isSuccessful() {
  122. return false;
  123. }
  124. },
  125. /**
  126. * Already up-to-date
  127. */
  128. UP_TO_DATE {
  129. @Override
  130. public boolean isSuccessful() {
  131. return true;
  132. }
  133. },
  134. /**
  135. * Fast-forward, HEAD points to the new commit
  136. */
  137. FAST_FORWARD {
  138. @Override
  139. public boolean isSuccessful() {
  140. return true;
  141. }
  142. },
  143. /**
  144. * Continue with nothing left to commit (possibly want skip).
  145. *
  146. * @since 2.0
  147. */
  148. NOTHING_TO_COMMIT {
  149. @Override
  150. public boolean isSuccessful() {
  151. return false;
  152. }
  153. },
  154. /**
  155. * Interactive rebase has been prepared
  156. * @since 3.2
  157. */
  158. INTERACTIVE_PREPARED {
  159. @Override
  160. public boolean isSuccessful() {
  161. return false;
  162. }
  163. };
  164. /**
  165. * @return whether the status indicates a successful result
  166. */
  167. public abstract boolean isSuccessful();
  168. }
  169. static final RebaseResult OK_RESULT = new RebaseResult(Status.OK);
  170. static final RebaseResult ABORTED_RESULT = new RebaseResult(Status.ABORTED);
  171. static final RebaseResult UP_TO_DATE_RESULT = new RebaseResult(
  172. Status.UP_TO_DATE);
  173. static final RebaseResult FAST_FORWARD_RESULT = new RebaseResult(
  174. Status.FAST_FORWARD);
  175. static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult(
  176. Status.NOTHING_TO_COMMIT);
  177. static final RebaseResult INTERACTIVE_PREPARED_RESULT = new RebaseResult(
  178. Status.INTERACTIVE_PREPARED);
  179. private final Status status;
  180. private final RevCommit currentCommit;
  181. private Map<String, MergeFailureReason> failingPaths;
  182. private List<String> conflicts;
  183. private List<String> uncommittedChanges;
  184. private RebaseResult(Status status) {
  185. this.status = status;
  186. currentCommit = null;
  187. }
  188. private RebaseResult(Status status, RevCommit commit) {
  189. this.status = status;
  190. currentCommit = commit;
  191. }
  192. /**
  193. * Create <code>RebaseResult</code>
  194. *
  195. * @param status
  196. * @param commit
  197. * current commit
  198. * @return the RebaseResult
  199. */
  200. static RebaseResult result(RebaseResult.Status status,
  201. RevCommit commit) {
  202. return new RebaseResult(status, commit);
  203. }
  204. /**
  205. * Create <code>RebaseResult</code> with status {@link Status#FAILED}
  206. *
  207. * @param failingPaths
  208. * list of paths causing this rebase to fail
  209. * @return the RebaseResult
  210. */
  211. static RebaseResult failed(
  212. Map<String, MergeFailureReason> failingPaths) {
  213. RebaseResult result = new RebaseResult(Status.FAILED);
  214. result.failingPaths = failingPaths;
  215. return result;
  216. }
  217. /**
  218. * Create <code>RebaseResult</code> with status {@link Status#CONFLICTS}
  219. *
  220. * @param conflicts
  221. * the list of conflicting paths
  222. * @return the RebaseResult
  223. */
  224. static RebaseResult conflicts(List<String> conflicts) {
  225. RebaseResult result = new RebaseResult(Status.CONFLICTS);
  226. result.conflicts = conflicts;
  227. return result;
  228. }
  229. /**
  230. * Create <code>RebaseResult</code> with status
  231. * {@link Status#UNCOMMITTED_CHANGES}
  232. *
  233. * @param uncommittedChanges
  234. * the list of paths
  235. * @return the RebaseResult
  236. */
  237. static RebaseResult uncommittedChanges(List<String> uncommittedChanges) {
  238. RebaseResult result = new RebaseResult(Status.UNCOMMITTED_CHANGES);
  239. result.uncommittedChanges = uncommittedChanges;
  240. return result;
  241. }
  242. /**
  243. * @return the overall status
  244. */
  245. public Status getStatus() {
  246. return status;
  247. }
  248. /**
  249. * @return the current commit if status is {@link Status#STOPPED}, otherwise
  250. * <code>null</code>
  251. */
  252. public RevCommit getCurrentCommit() {
  253. return currentCommit;
  254. }
  255. /**
  256. * @return the list of paths causing this rebase to fail (see
  257. * {@link ResolveMerger#getFailingPaths()} for details) if status is
  258. * {@link Status#FAILED}, otherwise <code>null</code>
  259. */
  260. public Map<String, MergeFailureReason> getFailingPaths() {
  261. return failingPaths;
  262. }
  263. /**
  264. * @return the list of conflicts if status is {@link Status#CONFLICTS}
  265. */
  266. public List<String> getConflicts() {
  267. return conflicts;
  268. }
  269. /**
  270. * @return the list of uncommitted changes if status is
  271. * {@link Status#UNCOMMITTED_CHANGES}
  272. *
  273. * @since 3.2
  274. */
  275. public List<String> getUncommittedChanges() {
  276. return uncommittedChanges;
  277. }
  278. }