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 20KB

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