Allow to programmatically set FastForwardMode for PullCommand

Bug: 517847
Change-Id: I70d12dbe347a3d7a3528687ee04e52a2052bfb93
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
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 0f8eba2..aa97996 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 @@
 
 	private TagOpt tagOption;
 
+	private FastForwardMode fastForwardMode;
+
 	private FetchRecurseSubmodulesMode submoduleRecurseMode = null;
 
 	/**
@@ -350,11 +352,9 @@
 			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);
 		}
@@ -437,6 +437,27 @@
 	}
 
 	/**
+	 * 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.
 	 *
 	 * @param recurse
@@ -477,6 +498,9 @@
 	}
 
 	private FastForwardMode getFastForwardMode() {
+		if (fastForwardMode != null) {
+			return fastForwardMode;
+		}
 		Config config = repo.getConfig();
 		Merge ffMode = config.getEnum(Merge.values(),
 				ConfigConstants.CONFIG_PULL_SECTION, null,