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