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.

MergeCommand.java 19KB

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