View Javadoc
1   /*
2    * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
3    * Copyright (C) 2010-2014, Stefan Lay <stefan.lay@sap.com>
4    * Copyright (C) 2016, Laurent Delaigue <laurent.delaigue@obeo.fr>
5    * and other copyright owners as documented in the project's IP log.
6    *
7    * This program and the accompanying materials are made available
8    * under the terms of the Eclipse Distribution License v1.0 which
9    * accompanies this distribution, is reproduced below, and is
10   * available at http://www.eclipse.org/org/documents/edl-v10.php
11   *
12   * All rights reserved.
13   *
14   * Redistribution and use in source and binary forms, with or
15   * without modification, are permitted provided that the following
16   * conditions are met:
17   *
18   * - Redistributions of source code must retain the above copyright
19   *   notice, this list of conditions and the following disclaimer.
20   *
21   * - Redistributions in binary form must reproduce the above
22   *   copyright notice, this list of conditions and the following
23   *   disclaimer in the documentation and/or other materials provided
24   *   with the distribution.
25   *
26   * - Neither the name of the Eclipse Foundation, Inc. nor the
27   *   names of its contributors may be used to endorse or promote
28   *   products derived from this software without specific prior
29   *   written permission.
30   *
31   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
32   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
33   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
38   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
40   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
43   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44   */
45  package org.eclipse.jgit.api;
46  
47  import java.io.IOException;
48  import java.text.MessageFormat;
49  import java.util.Arrays;
50  import java.util.Collections;
51  import java.util.LinkedList;
52  import java.util.List;
53  import java.util.Locale;
54  import java.util.Map;
55  
56  import org.eclipse.jgit.annotations.Nullable;
57  import org.eclipse.jgit.api.MergeResult.MergeStatus;
58  import org.eclipse.jgit.api.errors.CheckoutConflictException;
59  import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
60  import org.eclipse.jgit.api.errors.GitAPIException;
61  import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
62  import org.eclipse.jgit.api.errors.JGitInternalException;
63  import org.eclipse.jgit.api.errors.NoHeadException;
64  import org.eclipse.jgit.api.errors.NoMessageException;
65  import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
66  import org.eclipse.jgit.dircache.DirCacheCheckout;
67  import org.eclipse.jgit.events.WorkingTreeModifiedEvent;
68  import org.eclipse.jgit.internal.JGitText;
69  import org.eclipse.jgit.lib.AnyObjectId;
70  import org.eclipse.jgit.lib.Config.ConfigEnum;
71  import org.eclipse.jgit.lib.Constants;
72  import org.eclipse.jgit.lib.NullProgressMonitor;
73  import org.eclipse.jgit.lib.ObjectId;
74  import org.eclipse.jgit.lib.ObjectIdRef;
75  import org.eclipse.jgit.lib.ProgressMonitor;
76  import org.eclipse.jgit.lib.Ref;
77  import org.eclipse.jgit.lib.Ref.Storage;
78  import org.eclipse.jgit.lib.RefUpdate;
79  import org.eclipse.jgit.lib.RefUpdate.Result;
80  import org.eclipse.jgit.lib.Repository;
81  import org.eclipse.jgit.merge.MergeConfig;
82  import org.eclipse.jgit.merge.MergeMessageFormatter;
83  import org.eclipse.jgit.merge.MergeStrategy;
84  import org.eclipse.jgit.merge.Merger;
85  import org.eclipse.jgit.merge.ResolveMerger;
86  import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
87  import org.eclipse.jgit.merge.SquashMessageFormatter;
88  import org.eclipse.jgit.revwalk.RevCommit;
89  import org.eclipse.jgit.revwalk.RevWalk;
90  import org.eclipse.jgit.revwalk.RevWalkUtils;
91  import org.eclipse.jgit.treewalk.FileTreeIterator;
92  import org.eclipse.jgit.util.StringUtils;
93  
94  /**
95   * A class used to execute a {@code Merge} command. It has setters for all
96   * supported options and arguments of this command and a {@link #call()} method
97   * to finally execute the command. Each instance of this class should only be
98   * used for one invocation of the command (means: one call to {@link #call()})
99   *
100  * @see <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
101  *      >Git documentation about Merge</a>
102  */
103 public class MergeCommand extends GitCommand<MergeResult> {
104 
105 	private MergeStrategy mergeStrategy = MergeStrategy.RECURSIVE;
106 
107 	private List<Ref> commits = new LinkedList<>();
108 
109 	private Boolean squash;
110 
111 	private FastForwardMode fastForwardMode;
112 
113 	private String message;
114 
115 	private ProgressMonitor monitor = NullProgressMonitor.INSTANCE;
116 
117 	/**
118 	 * The modes available for fast forward merges corresponding to the
119 	 * <code>--ff</code>, <code>--no-ff</code> and <code>--ff-only</code>
120 	 * options under <code>branch.&lt;name&gt;.mergeoptions</code>.
121 	 */
122 	public enum FastForwardMode implements ConfigEnum {
123 		/**
124 		 * Corresponds to the default --ff option (for a fast forward update the
125 		 * branch pointer only).
126 		 */
127 		FF,
128 		/**
129 		 * Corresponds to the --no-ff option (create a merge commit even for a
130 		 * fast forward).
131 		 */
132 		NO_FF,
133 		/**
134 		 * Corresponds to the --ff-only option (abort unless the merge is a fast
135 		 * forward).
136 		 */
137 		FF_ONLY;
138 
139 		@Override
140 		public String toConfigValue() {
141 			return "--" + name().toLowerCase(Locale.ROOT).replace('_', '-'); //$NON-NLS-1$
142 		}
143 
144 		@Override
145 		public boolean matchConfigValue(String in) {
146 			if (StringUtils.isEmptyOrNull(in))
147 				return false;
148 			if (!in.startsWith("--")) //$NON-NLS-1$
149 				return false;
150 			return name().equalsIgnoreCase(in.substring(2).replace('-', '_'));
151 		}
152 
153 		/**
154 		 * The modes available for fast forward merges corresponding to the
155 		 * options under <code>merge.ff</code>.
156 		 */
157 		public enum Merge {
158 			/**
159 			 * {@link FastForwardMode#FF}.
160 			 */
161 			TRUE,
162 			/**
163 			 * {@link FastForwardMode#NO_FF}.
164 			 */
165 			FALSE,
166 			/**
167 			 * {@link FastForwardMode#FF_ONLY}.
168 			 */
169 			ONLY;
170 
171 			/**
172 			 * Map from <code>FastForwardMode</code> to
173 			 * <code>FastForwardMode.Merge</code>.
174 			 *
175 			 * @param ffMode
176 			 *            the <code>FastForwardMode</code> value to be mapped
177 			 * @return the mapped <code>FastForwardMode.Merge</code> value
178 			 */
179 			public static Merge valueOf(FastForwardMode ffMode) {
180 				switch (ffMode) {
181 				case NO_FF:
182 					return FALSE;
183 				case FF_ONLY:
184 					return ONLY;
185 				default:
186 					return TRUE;
187 				}
188 			}
189 		}
190 
191 		/**
192 		 * Map from <code>FastForwardMode.Merge</code> to
193 		 * <code>FastForwardMode</code>.
194 		 *
195 		 * @param ffMode
196 		 *            the <code>FastForwardMode.Merge</code> value to be mapped
197 		 * @return the mapped <code>FastForwardMode</code> value
198 		 */
199 		public static FastForwardMode valueOf(FastForwardMode.Merge ffMode) {
200 			switch (ffMode) {
201 			case FALSE:
202 				return NO_FF;
203 			case ONLY:
204 				return FF_ONLY;
205 			default:
206 				return FF;
207 			}
208 		}
209 	}
210 
211 	private Boolean commit;
212 
213 	/**
214 	 * @param repo
215 	 */
216 	protected MergeCommand(Repository repo) {
217 		super(repo);
218 	}
219 
220 	/**
221 	 * Executes the {@code Merge} command with all the options and parameters
222 	 * collected by the setter methods (e.g. {@link #include(Ref)}) of this
223 	 * class. Each instance of this class should only be used for one invocation
224 	 * of the command. Don't call this method twice on an instance.
225 	 *
226 	 * @return the result of the merge
227 	 */
228 	@Override
229 	@SuppressWarnings("boxing")
230 	public MergeResult call() throws GitAPIException, NoHeadException,
231 			ConcurrentRefUpdateException, CheckoutConflictException,
232 			InvalidMergeHeadsException, WrongRepositoryStateException, NoMessageException {
233 		checkCallable();
234 		fallBackToConfiguration();
235 		checkParameters();
236 
237 		RevWalk revWalk = null;
238 		DirCacheCheckout dco = null;
239 		try {
240 			Ref head = repo.exactRef(Constants.HEAD);
241 			if (head == null)
242 				throw new NoHeadException(
243 						JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
244 			StringBuilder refLogMessage = new StringBuilder("merge "); //$NON-NLS-1$
245 
246 			// Check for FAST_FORWARD, ALREADY_UP_TO_DATE
247 			revWalk = new RevWalk(repo);
248 
249 			// we know for now there is only one commit
250 			Ref ref = commits.get(0);
251 
252 			refLogMessage.append(ref.getName());
253 
254 			// handle annotated tags
255 			ref = repo.peel(ref);
256 			ObjectId objectId = ref.getPeeledObjectId();
257 			if (objectId == null)
258 				objectId = ref.getObjectId();
259 
260 			RevCommit srcCommit = revWalk.lookupCommit(objectId);
261 
262 			ObjectId headId = head.getObjectId();
263 			if (headId == null) {
264 				revWalk.parseHeaders(srcCommit);
265 				dco = new DirCacheCheckout(repo,
266 						repo.lockDirCache(), srcCommit.getTree());
267 				dco.setFailOnConflict(true);
268 				dco.checkout();
269 				RefUpdate refUpdate = repo
270 						.updateRef(head.getTarget().getName());
271 				refUpdate.setNewObjectId(objectId);
272 				refUpdate.setExpectedOldObjectId(null);
273 				refUpdate.setRefLogMessage("initial pull", false); //$NON-NLS-1$
274 				if (refUpdate.update() != Result.NEW)
275 					throw new NoHeadException(
276 							JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
277 				setCallable(false);
278 				return new MergeResult(srcCommit, srcCommit, new ObjectId[] {
279 						null, srcCommit }, MergeStatus.FAST_FORWARD,
280 						mergeStrategy, null, null);
281 			}
282 
283 			RevCommit headCommit = revWalk.lookupCommit(headId);
284 
285 			if (revWalk.isMergedInto(srcCommit, headCommit)) {
286 				setCallable(false);
287 				return new MergeResult(headCommit, srcCommit, new ObjectId[] {
288 						headCommit, srcCommit },
289 						MergeStatus.ALREADY_UP_TO_DATE, mergeStrategy, null, null);
290 			} else if (revWalk.isMergedInto(headCommit, srcCommit)
291 					&& fastForwardMode != FastForwardMode.NO_FF) {
292 				// FAST_FORWARD detected: skip doing a real merge but only
293 				// update HEAD
294 				refLogMessage.append(": " + MergeStatus.FAST_FORWARD); //$NON-NLS-1$
295 				dco = new DirCacheCheckout(repo,
296 						headCommit.getTree(), repo.lockDirCache(),
297 						srcCommit.getTree());
298 				dco.setFailOnConflict(true);
299 				dco.checkout();
300 				String msg = null;
301 				ObjectId newHead, base = null;
302 				MergeStatus mergeStatus = null;
303 				if (!squash) {
304 					updateHead(refLogMessage, srcCommit, headId);
305 					newHead = base = srcCommit;
306 					mergeStatus = MergeStatus.FAST_FORWARD;
307 				} else {
308 					msg = JGitText.get().squashCommitNotUpdatingHEAD;
309 					newHead = base = headId;
310 					mergeStatus = MergeStatus.FAST_FORWARD_SQUASHED;
311 					List<RevCommit> squashedCommits = RevWalkUtils.find(
312 							revWalk, srcCommit, headCommit);
313 					String squashMessage = new SquashMessageFormatter().format(
314 							squashedCommits, head);
315 					repo.writeSquashCommitMsg(squashMessage);
316 				}
317 				setCallable(false);
318 				return new MergeResult(newHead, base, new ObjectId[] {
319 						headCommit, srcCommit }, mergeStatus, mergeStrategy,
320 						null, msg);
321 			} else {
322 				if (fastForwardMode == FastForwardMode.FF_ONLY) {
323 					return new MergeResult(headCommit, srcCommit,
324 							new ObjectId[] { headCommit, srcCommit },
325 							MergeStatus.ABORTED, mergeStrategy, null, null);
326 				}
327 				String mergeMessage = ""; //$NON-NLS-1$
328 				if (!squash) {
329 					if (message != null)
330 						mergeMessage = message;
331 					else
332 						mergeMessage = new MergeMessageFormatter().format(
333 							commits, head);
334 					repo.writeMergeCommitMsg(mergeMessage);
335 					repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
336 				} else {
337 					List<RevCommit> squashedCommits = RevWalkUtils.find(
338 							revWalk, srcCommit, headCommit);
339 					String squashMessage = new SquashMessageFormatter().format(
340 							squashedCommits, head);
341 					repo.writeSquashCommitMsg(squashMessage);
342 				}
343 				Merger merger = mergeStrategy.newMerger(repo);
344 				merger.setProgressMonitor(monitor);
345 				boolean noProblems;
346 				Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
347 				Map<String, MergeFailureReason> failingPaths = null;
348 				List<String> unmergedPaths = null;
349 				if (merger instanceof ResolveMerger) {
350 					ResolveMerger resolveMerger = (ResolveMerger) merger;
351 					resolveMerger.setCommitNames(new String[] {
352 							"BASE", "HEAD", ref.getName() }); //$NON-NLS-1$ //$NON-NLS-2$
353 					resolveMerger.setWorkingTreeIterator(new FileTreeIterator(repo));
354 					noProblems = merger.merge(headCommit, srcCommit);
355 					lowLevelResults = resolveMerger
356 							.getMergeResults();
357 					failingPaths = resolveMerger.getFailingPaths();
358 					unmergedPaths = resolveMerger.getUnmergedPaths();
359 					if (!resolveMerger.getModifiedFiles().isEmpty()) {
360 						repo.fireEvent(new WorkingTreeModifiedEvent(
361 								resolveMerger.getModifiedFiles(), null));
362 					}
363 				} else
364 					noProblems = merger.merge(headCommit, srcCommit);
365 				refLogMessage.append(": Merge made by "); //$NON-NLS-1$
366 				if (!revWalk.isMergedInto(headCommit, srcCommit))
367 					refLogMessage.append(mergeStrategy.getName());
368 				else
369 					refLogMessage.append("recursive"); //$NON-NLS-1$
370 				refLogMessage.append('.');
371 				if (noProblems) {
372 					dco = new DirCacheCheckout(repo,
373 							headCommit.getTree(), repo.lockDirCache(),
374 							merger.getResultTreeId());
375 					dco.setFailOnConflict(true);
376 					dco.checkout();
377 
378 					String msg = null;
379 					ObjectId newHeadId = null;
380 					MergeStatus mergeStatus = null;
381 					if (!commit && squash) {
382 						mergeStatus = MergeStatus.MERGED_SQUASHED_NOT_COMMITTED;
383 					}
384 					if (!commit && !squash) {
385 						mergeStatus = MergeStatus.MERGED_NOT_COMMITTED;
386 					}
387 					if (commit && !squash) {
388 						try (Git git = new Git(getRepository())) {
389 							newHeadId = git.commit()
390 									.setReflogComment(refLogMessage.toString())
391 									.call().getId();
392 						}
393 						mergeStatus = MergeStatus.MERGED;
394 						getRepository().autoGC(monitor);
395 					}
396 					if (commit && squash) {
397 						msg = JGitText.get().squashCommitNotUpdatingHEAD;
398 						newHeadId = headCommit.getId();
399 						mergeStatus = MergeStatus.MERGED_SQUASHED;
400 					}
401 					return new MergeResult(newHeadId, null,
402 							new ObjectId[] { headCommit.getId(),
403 									srcCommit.getId() }, mergeStatus,
404 							mergeStrategy, null, msg);
405 				} else {
406 					if (failingPaths != null) {
407 						repo.writeMergeCommitMsg(null);
408 						repo.writeMergeHeads(null);
409 						return new MergeResult(null, merger.getBaseCommitId(),
410 								new ObjectId[] {
411 										headCommit.getId(), srcCommit.getId() },
412 								MergeStatus.FAILED, mergeStrategy,
413 								lowLevelResults, failingPaths, null);
414 					} else {
415 						String mergeMessageWithConflicts = new MergeMessageFormatter()
416 								.formatWithConflicts(mergeMessage,
417 										unmergedPaths);
418 						repo.writeMergeCommitMsg(mergeMessageWithConflicts);
419 						return new MergeResult(null, merger.getBaseCommitId(),
420 								new ObjectId[] { headCommit.getId(),
421 										srcCommit.getId() },
422 								MergeStatus.CONFLICTING, mergeStrategy,
423 								lowLevelResults, null);
424 					}
425 				}
426 			}
427 		} catch (org.eclipse.jgit.errors.CheckoutConflictException e) {
428 			List<String> conflicts = (dco == null) ? Collections
429 					.<String> emptyList() : dco.getConflicts();
430 			throw new CheckoutConflictException(conflicts, e);
431 		} catch (IOException e) {
432 			throw new JGitInternalException(
433 					MessageFormat.format(
434 							JGitText.get().exceptionCaughtDuringExecutionOfMergeCommand,
435 							e), e);
436 		} finally {
437 			if (revWalk != null)
438 				revWalk.close();
439 		}
440 	}
441 
442 	private void checkParameters() throws InvalidMergeHeadsException {
443 		if (squash.booleanValue() && fastForwardMode == FastForwardMode.NO_FF) {
444 			throw new JGitInternalException(
445 					JGitText.get().cannotCombineSquashWithNoff);
446 		}
447 
448 		if (commits.size() != 1)
449 			throw new InvalidMergeHeadsException(
450 					commits.isEmpty() ? JGitText.get().noMergeHeadSpecified
451 							: MessageFormat.format(
452 									JGitText.get().mergeStrategyDoesNotSupportHeads,
453 									mergeStrategy.getName(),
454 									Integer.valueOf(commits.size())));
455 	}
456 
457 	/**
458 	 * Use values from the configuation if they have not been explicitly defined
459 	 * via the setters
460 	 */
461 	private void fallBackToConfiguration() {
462 		MergeConfig config = MergeConfig.getConfigForCurrentBranch(repo);
463 		if (squash == null)
464 			squash = Boolean.valueOf(config.isSquash());
465 		if (commit == null)
466 			commit = Boolean.valueOf(config.isCommit());
467 		if (fastForwardMode == null)
468 			fastForwardMode = config.getFastForwardMode();
469 	}
470 
471 	private void updateHead(StringBuilder refLogMessage, ObjectId newHeadId,
472 			ObjectId oldHeadID) throws IOException,
473 			ConcurrentRefUpdateException {
474 		RefUpdate refUpdate = repo.updateRef(Constants.HEAD);
475 		refUpdate.setNewObjectId(newHeadId);
476 		refUpdate.setRefLogMessage(refLogMessage.toString(), false);
477 		refUpdate.setExpectedOldObjectId(oldHeadID);
478 		Result rc = refUpdate.update();
479 		switch (rc) {
480 		case NEW:
481 		case FAST_FORWARD:
482 			return;
483 		case REJECTED:
484 		case LOCK_FAILURE:
485 			throw new ConcurrentRefUpdateException(
486 					JGitText.get().couldNotLockHEAD, refUpdate.getRef(), rc);
487 		default:
488 			throw new JGitInternalException(MessageFormat.format(
489 					JGitText.get().updatingRefFailed, Constants.HEAD,
490 					newHeadId.toString(), rc));
491 		}
492 	}
493 
494 	/**
495 	 *
496 	 * @param mergeStrategy
497 	 *            the {@link MergeStrategy} to be used
498 	 * @return {@code this}
499 	 */
500 	public MergeCommand setStrategy(MergeStrategy mergeStrategy) {
501 		checkCallable();
502 		this.mergeStrategy = mergeStrategy;
503 		return this;
504 	}
505 
506 	/**
507 	 * @param aCommit
508 	 *            a reference to a commit which is merged with the current head
509 	 * @return {@code this}
510 	 */
511 	public MergeCommand include(Ref aCommit) {
512 		checkCallable();
513 		commits.add(aCommit);
514 		return this;
515 	}
516 
517 	/**
518 	 * @param aCommit
519 	 *            the Id of a commit which is merged with the current head
520 	 * @return {@code this}
521 	 */
522 	public MergeCommand include(AnyObjectId aCommit) {
523 		return include(aCommit.getName(), aCommit);
524 	}
525 
526 	/**
527 	 * @param name
528 	 *            a name given to the commit
529 	 * @param aCommit
530 	 *            the Id of a commit which is merged with the current head
531 	 * @return {@code this}
532 	 */
533 	public MergeCommand include(String name, AnyObjectId aCommit) {
534 		return include(new ObjectIdRef.Unpeeled(Storage.LOOSE, name,
535 				aCommit.copy()));
536 	}
537 
538 	/**
539 	 * If <code>true</code>, will prepare the next commit in working tree and
540 	 * index as if a real merge happened, but do not make the commit or move the
541 	 * HEAD. Otherwise, perform the merge and commit the result.
542 	 * <p>
543 	 * In case the merge was successful but this flag was set to
544 	 * <code>true</code> a {@link MergeResult} with status
545 	 * {@link MergeStatus#MERGED_SQUASHED} or
546 	 * {@link MergeStatus#FAST_FORWARD_SQUASHED} is returned.
547 	 *
548 	 * @param squash
549 	 *            whether to squash commits or not
550 	 * @return {@code this}
551 	 * @since 2.0
552 	 */
553 	public MergeCommand setSquash(boolean squash) {
554 		checkCallable();
555 		this.squash = Boolean.valueOf(squash);
556 		return this;
557 	}
558 
559 	/**
560 	 * Sets the fast forward mode.
561 	 *
562 	 * @param fastForwardMode
563 	 *            corresponds to the --ff/--no-ff/--ff-only options. If
564 	 *            {@code null} use the value of the {@code merge.ff} option
565 	 *            configured in git config. If this option is not configured
566 	 *            --ff is the built-in default.
567 	 * @return {@code this}
568 	 * @since 2.2
569 	 */
570 	public MergeCommand setFastForward(
571 			@Nullable FastForwardMode fastForwardMode) {
572 		checkCallable();
573 		this.fastForwardMode = fastForwardMode;
574 		return this;
575 	}
576 
577 	/**
578 	 * Controls whether the merge command should automatically commit after a
579 	 * successful merge
580 	 *
581 	 * @param commit
582 	 *            <code>true</code> if this command should commit (this is the
583 	 *            default behavior). <code>false</code> if this command should
584 	 *            not commit. In case the merge was successful but this flag was
585 	 *            set to <code>false</code> a {@link MergeResult} with type
586 	 *            {@link MergeResult} with status
587 	 *            {@link MergeStatus#MERGED_NOT_COMMITTED} is returned
588 	 * @return {@code this}
589 	 * @since 3.0
590 	 */
591 	public MergeCommand setCommit(boolean commit) {
592 		this.commit = Boolean.valueOf(commit);
593 		return this;
594 	}
595 
596 	/**
597 	 * Set the commit message to be used for the merge commit (in case one is
598 	 * created)
599 	 *
600 	 * @param message
601 	 *            the message to be used for the merge commit
602 	 * @return {@code this}
603 	 * @since 3.5
604 	 */
605 	public MergeCommand setMessage(String message) {
606 		this.message = message;
607 		return this;
608 	}
609 
610 	/**
611 	 * The progress monitor associated with the diff operation. By default, this
612 	 * is set to <code>NullProgressMonitor</code>
613 	 *
614 	 * @see NullProgressMonitor
615 	 *
616 	 * @param monitor
617 	 *            A progress monitor
618 	 * @return this instance
619 	 * @since 4.2
620 	 */
621 	public MergeCommand setProgressMonitor(ProgressMonitor monitor) {
622 		if (monitor == null) {
623 			monitor = NullProgressMonitor.INSTANCE;
624 		}
625 		this.monitor = monitor;
626 		return this;
627 	}
628 }