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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. * Applying stash resulted in conflicts
  166. *
  167. * @since 3.2
  168. */
  169. STASH_APPLY_CONFLICTS {
  170. @Override
  171. public boolean isSuccessful() {
  172. return true;
  173. }
  174. };
  175. /**
  176. * @return whether the status indicates a successful result
  177. */
  178. public abstract boolean isSuccessful();
  179. }
  180. static final RebaseResult OK_RESULT = new RebaseResult(Status.OK);
  181. static final RebaseResult ABORTED_RESULT = new RebaseResult(Status.ABORTED);
  182. static final RebaseResult UP_TO_DATE_RESULT = new RebaseResult(
  183. Status.UP_TO_DATE);
  184. static final RebaseResult FAST_FORWARD_RESULT = new RebaseResult(
  185. Status.FAST_FORWARD);
  186. static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult(
  187. Status.NOTHING_TO_COMMIT);
  188. static final RebaseResult INTERACTIVE_PREPARED_RESULT = new RebaseResult(
  189. Status.INTERACTIVE_PREPARED);
  190. static final RebaseResult STASH_APPLY_CONFLICTS_RESULT = new RebaseResult(
  191. Status.STASH_APPLY_CONFLICTS);
  192. private final Status status;
  193. private final RevCommit currentCommit;
  194. private Map<String, MergeFailureReason> failingPaths;
  195. private List<String> conflicts;
  196. private List<String> uncommittedChanges;
  197. private RebaseResult(Status status) {
  198. this.status = status;
  199. currentCommit = null;
  200. }
  201. private RebaseResult(Status status, RevCommit commit) {
  202. this.status = status;
  203. currentCommit = commit;
  204. }
  205. /**
  206. * Create <code>RebaseResult</code>
  207. *
  208. * @param status
  209. * @param commit
  210. * current commit
  211. * @return the RebaseResult
  212. */
  213. static RebaseResult result(RebaseResult.Status status,
  214. RevCommit commit) {
  215. return new RebaseResult(status, commit);
  216. }
  217. /**
  218. * Create <code>RebaseResult</code> with status {@link Status#FAILED}
  219. *
  220. * @param failingPaths
  221. * list of paths causing this rebase to fail
  222. * @return the RebaseResult
  223. */
  224. static RebaseResult failed(
  225. Map<String, MergeFailureReason> failingPaths) {
  226. RebaseResult result = new RebaseResult(Status.FAILED);
  227. result.failingPaths = failingPaths;
  228. return result;
  229. }
  230. /**
  231. * Create <code>RebaseResult</code> with status {@link Status#CONFLICTS}
  232. *
  233. * @param conflicts
  234. * the list of conflicting paths
  235. * @return the RebaseResult
  236. */
  237. static RebaseResult conflicts(List<String> conflicts) {
  238. RebaseResult result = new RebaseResult(Status.CONFLICTS);
  239. result.conflicts = conflicts;
  240. return result;
  241. }
  242. /**
  243. * Create <code>RebaseResult</code> with status
  244. * {@link Status#UNCOMMITTED_CHANGES}
  245. *
  246. * @param uncommittedChanges
  247. * the list of paths
  248. * @return the RebaseResult
  249. */
  250. static RebaseResult uncommittedChanges(List<String> uncommittedChanges) {
  251. RebaseResult result = new RebaseResult(Status.UNCOMMITTED_CHANGES);
  252. result.uncommittedChanges = uncommittedChanges;
  253. return result;
  254. }
  255. /**
  256. * @return the overall status
  257. */
  258. public Status getStatus() {
  259. return status;
  260. }
  261. /**
  262. * @return the current commit if status is {@link Status#STOPPED}, otherwise
  263. * <code>null</code>
  264. */
  265. public RevCommit getCurrentCommit() {
  266. return currentCommit;
  267. }
  268. /**
  269. * @return the list of paths causing this rebase to fail (see
  270. * {@link ResolveMerger#getFailingPaths()} for details) if status is
  271. * {@link Status#FAILED}, otherwise <code>null</code>
  272. */
  273. public Map<String, MergeFailureReason> getFailingPaths() {
  274. return failingPaths;
  275. }
  276. /**
  277. * @return the list of conflicts if status is {@link Status#CONFLICTS}
  278. */
  279. public List<String> getConflicts() {
  280. return conflicts;
  281. }
  282. /**
  283. * @return the list of uncommitted changes if status is
  284. * {@link Status#UNCOMMITTED_CHANGES}
  285. *
  286. * @since 3.2
  287. */
  288. public List<String> getUncommittedChanges() {
  289. return uncommittedChanges;
  290. }
  291. }