From 032eef5b12a25e0da48004eea589966ae0652433 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 21 Apr 2023 08:51:08 +0200 Subject: [PATCH] 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 --- .../org/eclipse/jgit/api/PullCommandTest.java | 15 +++++++ .../eclipse/jgit/lib/BranchConfigTest.java | 45 ++++++++++++++++++- .../org/eclipse/jgit/lib/BranchConfig.java | 7 ++- 3 files changed, 65 insertions(+), 2 deletions(-) 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 7a0ffdbec..12300b339 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 @@ -393,6 +393,21 @@ public void testPullWithRebaseMerges1Config() throws Exception { doTestPullWithRebase(setup, TestPullMode.REBASE_MERGES); } + @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 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 { 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 1374ea261..2c9097f37 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 { @@ -113,6 +115,38 @@ public void getTrackingBranchShouldHandleNormalCaseForRemoteTrackingBranch() { branchConfig.getTrackingBranch()); } + @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("" // @@ -120,11 +154,20 @@ public void isRebase() { + "[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 19495dff1..e15c7af93 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 */