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