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
45 import java.util.List;
46 import java.util.Map;
47
48 import org.eclipse.jgit.merge.ResolveMerger;
49 import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
50 import org.eclipse.jgit.revwalk.RevCommit;
51
52 /**
53 * The result of a {@link RebaseCommand} execution
54 */
55 public class RebaseResult {
56 /**
57 * The overall status
58 */
59 public enum Status {
60 /**
61 * Rebase was successful, HEAD points to the new commit
62 */
63 OK {
64 @Override
65 public boolean isSuccessful() {
66 return true;
67 }
68 },
69 /**
70 * Aborted; the original HEAD was restored
71 */
72 ABORTED {
73 @Override
74 public boolean isSuccessful() {
75 return false;
76 }
77 },
78 /**
79 * Stopped due to a conflict; must either abort or resolve or skip
80 */
81 STOPPED {
82 @Override
83 public boolean isSuccessful() {
84 return false;
85 }
86 },
87 /**
88 * Stopped for editing in the context of an interactive rebase
89 *
90 * @since 3.2
91 */
92 EDIT {
93 @Override
94 public boolean isSuccessful() {
95 return false;
96 }
97 },
98 /**
99 * Failed; the original HEAD was restored
100 */
101 FAILED {
102 @Override
103 public boolean isSuccessful() {
104 return false;
105 }
106 },
107 /**
108 * The repository contains uncommitted changes and the rebase is not a
109 * fast-forward
110 *
111 * @since 3.2
112 */
113 UNCOMMITTED_CHANGES {
114 @Override
115 public boolean isSuccessful() {
116 return false;
117 }
118 },
119 /**
120 * Conflicts: checkout of target HEAD failed
121 */
122 CONFLICTS {
123 @Override
124 public boolean isSuccessful() {
125 return false;
126 }
127 },
128 /**
129 * Already up-to-date
130 */
131 UP_TO_DATE {
132 @Override
133 public boolean isSuccessful() {
134 return true;
135 }
136 },
137 /**
138 * Fast-forward, HEAD points to the new commit
139 */
140 FAST_FORWARD {
141 @Override
142 public boolean isSuccessful() {
143 return true;
144 }
145 },
146
147 /**
148 * Continue with nothing left to commit (possibly want skip).
149 *
150 * @since 2.0
151 */
152 NOTHING_TO_COMMIT {
153 @Override
154 public boolean isSuccessful() {
155 return false;
156 }
157 },
158
159 /**
160 * Interactive rebase has been prepared
161 * @since 3.2
162 */
163 INTERACTIVE_PREPARED {
164 @Override
165 public boolean isSuccessful() {
166 return false;
167 }
168 },
169
170 /**
171 * Applying stash resulted in conflicts
172 *
173 * @since 3.2
174 */
175 STASH_APPLY_CONFLICTS {
176 @Override
177 public boolean isSuccessful() {
178 return true;
179 }
180 };
181
182 /**
183 * @return whether the status indicates a successful result
184 */
185 public abstract boolean isSuccessful();
186 }
187
188 static final RebaseResult OK_RESULT = new RebaseResult(Status.OK);
189
190 static final RebaseResult ABORTED_RESULT = new RebaseResult(Status.ABORTED);
191
192 static final RebaseResult UP_TO_DATE_RESULT = new RebaseResult(
193 Status.UP_TO_DATE);
194
195 static final RebaseResult FAST_FORWARD_RESULT = new RebaseResult(
196 Status.FAST_FORWARD);
197
198 static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult(
199 Status.NOTHING_TO_COMMIT);
200
201 static final RebaseResult INTERACTIVE_PREPARED_RESULT = new RebaseResult(
202 Status.INTERACTIVE_PREPARED);
203
204 static final RebaseResult STASH_APPLY_CONFLICTS_RESULT = new RebaseResult(
205 Status.STASH_APPLY_CONFLICTS);
206
207 private final Status status;
208
209 private final RevCommit currentCommit;
210
211 private Map<String, MergeFailureReason> failingPaths;
212
213 private List<String> conflicts;
214
215 private List<String> uncommittedChanges;
216
217 private RebaseResult(Status status) {
218 this.status = status;
219 currentCommit = null;
220 }
221
222 private RebaseResult(Status status, RevCommit commit) {
223 this.status = status;
224 currentCommit = commit;
225 }
226
227 /**
228 * Create <code>RebaseResult</code>
229 *
230 * @param status
231 * @param commit
232 * current commit
233 * @return the RebaseResult
234 */
235 static RebaseResult result(RebaseResult.Status status,
236 RevCommit commit) {
237 return new RebaseResult(status, commit);
238 }
239
240 /**
241 * Create <code>RebaseResult</code> with status {@link Status#FAILED}
242 *
243 * @param failingPaths
244 * list of paths causing this rebase to fail
245 * @return the RebaseResult
246 */
247 static RebaseResult failed(
248 Map<String, MergeFailureReason> failingPaths) {
249 RebaseResult result = new RebaseResult(Status.FAILED);
250 result.failingPaths = failingPaths;
251 return result;
252 }
253
254 /**
255 * Create <code>RebaseResult</code> with status {@link Status#CONFLICTS}
256 *
257 * @param conflicts
258 * the list of conflicting paths
259 * @return the RebaseResult
260 */
261 static RebaseResult conflicts(List<String> conflicts) {
262 RebaseResult result = new RebaseResult(Status.CONFLICTS);
263 result.conflicts = conflicts;
264 return result;
265 }
266
267 /**
268 * Create <code>RebaseResult</code> with status
269 * {@link Status#UNCOMMITTED_CHANGES}
270 *
271 * @param uncommittedChanges
272 * the list of paths
273 * @return the RebaseResult
274 */
275 static RebaseResult uncommittedChanges(List<String> uncommittedChanges) {
276 RebaseResult result = new RebaseResult(Status.UNCOMMITTED_CHANGES);
277 result.uncommittedChanges = uncommittedChanges;
278 return result;
279 }
280
281 /**
282 * @return the overall status
283 */
284 public Status getStatus() {
285 return status;
286 }
287
288 /**
289 * @return the current commit if status is {@link Status#STOPPED}, otherwise
290 * <code>null</code>
291 */
292 public RevCommit getCurrentCommit() {
293 return currentCommit;
294 }
295
296 /**
297 * @return the list of paths causing this rebase to fail (see
298 * {@link ResolveMerger#getFailingPaths()} for details) if status is
299 * {@link Status#FAILED}, otherwise <code>null</code>
300 */
301 public Map<String, MergeFailureReason> getFailingPaths() {
302 return failingPaths;
303 }
304
305 /**
306 * @return the list of conflicts if status is {@link Status#CONFLICTS}
307 */
308 public List<String> getConflicts() {
309 return conflicts;
310 }
311
312 /**
313 * @return the list of uncommitted changes if status is
314 * {@link Status#UNCOMMITTED_CHANGES}
315 *
316 * @since 3.2
317 */
318 public List<String> getUncommittedChanges() {
319 return uncommittedChanges;
320 }
321
322 }