From df638e0cfc628469eee9a91df5b2b65634e274d7 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 12 Jun 2017 19:29:55 +0200 Subject: [PATCH] Allow to programmatically set FastForwardMode for PullCommand Bug: 517847 Change-Id: I70d12dbe347a3d7a3528687ee04e52a2052bfb93 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/api/PullCommand.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java index 0f8eba2332..aa97996dfc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -99,6 +99,8 @@ public class PullCommand extends TransportCommand { private TagOpt tagOption; + private FastForwardMode fastForwardMode; + private FetchRecurseSubmodulesMode submoduleRecurseMode = null; /** @@ -350,11 +352,9 @@ public class PullCommand extends TransportCommand { result = new PullResult(fetchRes, remote, rebaseRes); } else { MergeCommand merge = new MergeCommand(repo); - merge.include(upstreamName, commitToMerge); - merge.setStrategy(strategy); - merge.setProgressMonitor(monitor); - merge.setFastForward(getFastForwardMode()); - MergeResult mergeRes = merge.call(); + MergeResult mergeRes = merge.include(upstreamName, commitToMerge) + .setStrategy(strategy).setProgressMonitor(monitor) + .setFastForward(getFastForwardMode()).call(); monitor.update(1); result = new PullResult(fetchRes, remote, mergeRes); } @@ -436,6 +436,27 @@ public class PullCommand extends TransportCommand { return this; } + /** + * Sets the fast forward mode. It is used if pull is configured to do a + * merge as opposed to rebase. If non-{@code null} takes precedence over the + * fast-forward mode configured in git config. + * + * @param fastForwardMode + * corresponds to the --ff/--no-ff/--ff-only options. If + * {@code null} use the value of {@code pull.ff} configured in + * git config. If {@code pull.ff} is not configured fall back to + * the value of {@code merge.ff}. If {@code merge.ff} is not + * configured --ff is the built-in default. + * @return {@code this} + * @since 4.9 + */ + public PullCommand setFastForward( + @Nullable FastForwardMode fastForwardMode) { + checkCallable(); + this.fastForwardMode = fastForwardMode; + return this; + } + /** * Set the mode to be used for recursing into submodules. * @@ -477,6 +498,9 @@ public class PullCommand extends TransportCommand { } private FastForwardMode getFastForwardMode() { + if (fastForwardMode != null) { + return fastForwardMode; + } Config config = repo.getConfig(); Merge ffMode = config.getEnum(Merge.values(), ConfigConstants.CONFIG_PULL_SECTION, null, -- 2.39.5