aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-04-21 08:51:08 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-22 23:43:40 +0200
commit032eef5b12a25e0da48004eea589966ae0652433 (patch)
tree6cd32787ed0a5c43879372c0852b4f4512417c54
parent06b40b95c2ac28595624e1672949d245aef11fe0 (diff)
downloadjgit-032eef5b12a25e0da48004eea589966ae0652433.tar.gz
jgit-032eef5b12a25e0da48004eea589966ae0652433.zip
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
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java15
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/BranchConfigTest.java45
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java7
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 7a0ffdbeca..12300b3390 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 class PullCommandTest extends RepositoryTestCase {
}
@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 1374ea2619..2c9097f377 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 @@ package org.eclipse.jgit.lib;
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 class BranchConfigTest {
}
@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 19495dff1f..e15c7af932 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 class BranchConfig {
*
* @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 */