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.6KB

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