Parse pull.rebase=preserve as alias for pull.rebase=merges

This ensures backwards compatibility to the old config value which was
removed in git 2.34 which JGit followed in Ic07ff954e2.

Change-Id: I2b4e27fd71898b6e0e227e406c40682bd9786cd4
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 7a0ffdb..12300b3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -394,6 +394,21 @@ public void testPullWithRebaseMerges1Config() throws Exception {
 	}
 
 	@Test
+	/**
+	 * global rebase config using old "preserve" value which was renamed to
+	 * "merges" should be respected to ensure backwards compatibility
+	 */
+	public void testPullWithRebaseMerges1ConfigAlias() throws Exception {
+		Callable<PullResult> setup = () -> {
+			StoredConfig config = dbTarget.getConfig();
+			config.setString("pull", null, "rebase", "preserve");
+			config.save();
+			return target.pull().call();
+		};
+		doTestPullWithRebase(setup, TestPullMode.REBASE_MERGES);
+	}
+
+	@Test
 	/** the branch-local config should win over the global config */
 	public void testPullWithRebaseMergesConfig2() throws Exception {
 		Callable<PullResult> setup = () -> {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
index 1374ea2..2c9097f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java
@@ -14,9 +14,11 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.lib.BranchConfig.BranchRebaseMode;
 import org.junit.Test;
 
 public class BranchConfigTest {
@@ -114,17 +116,58 @@ public void getTrackingBranchShouldHandleNormalCaseForRemoteTrackingBranch() {
 	}
 
 	@Test
+	public void testRebaseMode() {
+		Config c = parse("" //
+				+ "[branch \"undefined\"]\n"
+				+ "[branch \"false\"]\n"
+				+ "  rebase = false\n"
+				+ "[branch \"true\"]\n"
+				+ "  rebase = true\n"
+				+ "[branch \"interactive\"]\n"
+				+ "  rebase = interactive\n"
+				+ "[branch \"merges\"]\n"
+				+ "  rebase = merges\n"
+				+ "[branch \"preserve\"]\n"
+				+ "  rebase = preserve\n"
+				+ "[branch \"illegal\"]\n"
+				+ "  rebase = illegal\n");
+		assertEquals(BranchRebaseMode.NONE,
+				new BranchConfig(c, " undefined").getRebaseMode());
+		assertEquals(BranchRebaseMode.NONE,
+				new BranchConfig(c, "false").getRebaseMode());
+		assertEquals(BranchRebaseMode.REBASE,
+				new BranchConfig(c, "true").getRebaseMode());
+		assertEquals(BranchRebaseMode.INTERACTIVE,
+				new BranchConfig(c, "interactive").getRebaseMode());
+		assertEquals(BranchRebaseMode.MERGES,
+				new BranchConfig(c, "merges").getRebaseMode());
+		assertEquals(BranchRebaseMode.MERGES,
+				new BranchConfig(c, "preserve").getRebaseMode());
+		assertThrows(IllegalArgumentException.class,
+				() -> new BranchConfig(c, "illegal").getRebaseMode());
+	}
+
+	@Test
 	public void isRebase() {
 		Config c = parse("" //
 				+ "[branch \"undefined\"]\n"
 				+ "[branch \"false\"]\n"
 				+ "  rebase = false\n"
 				+ "[branch \"true\"]\n"
-				+ "  rebase = true\n");
+				+ "  rebase = true\n"
+				+ "[branch \"interactive\"]\n"
+				+ "  rebase = interactive\n"
+				+ "[branch \"merges\"]\n"
+				+ "  rebase = merges\n"
+				+ "[branch \"preserve\"]\n"
+				+ "  rebase = preserve\n");
 
 		assertFalse(new BranchConfig(c, "undefined").isRebase());
 		assertFalse(new BranchConfig(c, "false").isRebase());
 		assertTrue(new BranchConfig(c, "true").isRebase());
+		assertTrue(new BranchConfig(c, "interactive").isRebase());
+		assertTrue(new BranchConfig(c, "merges").isRebase());
+		assertTrue(new BranchConfig(c, "preserve").isRebase());
 	}
 
 	private static Config parse(String content) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
index 19495df..e15c7af 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java
@@ -35,7 +35,12 @@ public enum BranchRebaseMode implements Config.ConfigEnum {
 		 *
 		 * @since 6.5 used instead of deprecated "preserve" option
 		 */
-		MERGES("merges"), //$NON-NLS-1$
+		MERGES("merges"){ //$NON-NLS-1$
+		    @Override
+		    public boolean matchConfigValue(String s) {
+		      return super.matchConfigValue(s) || "preserve".equals(s); //$NON-NLS-1$
+		    }
+		},
 		/** Value for rebasing interactively */
 		INTERACTIVE("interactive"), //$NON-NLS-1$
 		/** Value for not rebasing at all but merging */