aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2022-02-09 18:33:31 +0100
committerThomas Wolf <thomas.wolf@paranor.ch>2022-02-09 18:33:31 +0100
commit2883762219e37dc88d7592b4b8f7d5b115baac04 (patch)
tree03f7dcf9d2b4ab623d06b4dada2949a9753ee3c4
parent0d2825cdcdecd5c55fb9e6fc4c54f7c8d994f1bf (diff)
downloadjgit-2883762219e37dc88d7592b4b8f7d5b115baac04.tar.gz
jgit-2883762219e37dc88d7592b4b8f7d5b115baac04.zip
Support for git config push.default
Enhance the (unused!?) PushConfig; include a PushDefault enumeration. Add simple tests for this PushConfig. Bug: 351314 Change-Id: Ibc5656a2a1fccf70d00c5e15de8ed3dd8add6337 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java60
-rw-r--r--org.eclipse.jgit/.settings/.api_filters8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java104
4 files changed, 183 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java
index 6109d6cb4d..cbc1d546ac 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConfigTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017, David Pursehouse <david.pursehouse@gmail.com> and others
+ * Copyright (C) 2017, 2022 David Pursehouse <david.pursehouse@gmail.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -14,10 +14,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.transport.PushConfig.PushDefault;
import org.eclipse.jgit.transport.PushConfig.PushRecurseSubmodulesMode;
import org.junit.Test;
public class PushConfigTest {
+
@Test
public void pushRecurseSubmoduleMatch() throws Exception {
assertTrue(PushRecurseSubmodulesMode.CHECK.matchConfigValue("check"));
@@ -52,4 +55,59 @@ public class PushConfigTest {
assertEquals("check", PushRecurseSubmodulesMode.CHECK.toConfigValue());
assertEquals("false", PushRecurseSubmodulesMode.NO.toConfigValue());
}
+
+ @Test
+ public void pushDefaultMatch() throws Exception {
+ assertTrue(PushDefault.NOTHING.matchConfigValue("nothing"));
+ assertTrue(PushDefault.NOTHING.matchConfigValue("NOTHING"));
+ assertTrue(PushDefault.CURRENT.matchConfigValue("current"));
+ assertTrue(PushDefault.CURRENT.matchConfigValue("CURRENT"));
+ assertTrue(PushDefault.UPSTREAM.matchConfigValue("upstream"));
+ assertTrue(PushDefault.UPSTREAM.matchConfigValue("UPSTREAM"));
+ assertTrue(PushDefault.UPSTREAM.matchConfigValue("tracking"));
+ assertTrue(PushDefault.UPSTREAM.matchConfigValue("TRACKING"));
+ assertTrue(PushDefault.SIMPLE.matchConfigValue("simple"));
+ assertTrue(PushDefault.SIMPLE.matchConfigValue("SIMPLE"));
+ assertTrue(PushDefault.MATCHING.matchConfigValue("matching"));
+ assertTrue(PushDefault.MATCHING.matchConfigValue("MATCHING"));
+ }
+
+ @Test
+ public void pushDefaultNoMatch() throws Exception {
+ assertFalse(PushDefault.NOTHING.matchConfigValue("n"));
+ assertFalse(PushDefault.CURRENT.matchConfigValue(""));
+ assertFalse(PushDefault.UPSTREAM.matchConfigValue("track"));
+ }
+
+ @Test
+ public void pushDefaultToConfigValue() throws Exception {
+ assertEquals("nothing", PushDefault.NOTHING.toConfigValue());
+ assertEquals("current", PushDefault.CURRENT.toConfigValue());
+ assertEquals("upstream", PushDefault.UPSTREAM.toConfigValue());
+ assertEquals("simple", PushDefault.SIMPLE.toConfigValue());
+ assertEquals("matching", PushDefault.MATCHING.toConfigValue());
+ }
+
+ @Test
+ public void testEmptyConfig() throws Exception {
+ PushConfig cfg = parse("");
+ assertEquals(PushRecurseSubmodulesMode.NO, cfg.getRecurseSubmodules());
+ assertEquals(PushDefault.SIMPLE, cfg.getPushDefault());
+ }
+
+ @Test
+ public void testConfig() throws Exception {
+ PushConfig cfg = parse(
+ "[push]\n\tdefault = tracking\n\trecurseSubmodules = on-demand\n");
+ assertEquals(PushRecurseSubmodulesMode.ON_DEMAND,
+ cfg.getRecurseSubmodules());
+ assertEquals(PushDefault.UPSTREAM, cfg.getPushDefault());
+ }
+
+ private static PushConfig parse(String content) throws Exception {
+ Config c = new Config();
+ c.fromText(content);
+ return c.get(PushConfig::new);
+ }
+
}
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index cdf17402a5..792a0c91c2 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -17,4 +17,12 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/jgit/transport/PushConfig.java" type="org.eclipse.jgit.transport.PushConfig">
+ <filter id="338722907">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.transport.PushConfig"/>
+ <message_argument value="PushConfig()"/>
+ </message_arguments>
+ </filter>
+ </resource>
</component>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
index af2b4ccdd1..205999f8c9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
@@ -808,4 +808,18 @@ public final class ConfigConstants {
*/
public static final String CONFIG_KEY_SEARCH_FOR_REUSE_TIMEOUT = "searchforreusetimeout";
+ /**
+ * The "push" section.
+ *
+ * @since 6.1
+ */
+ public static final String CONFIG_PUSH_SECTION = "push";
+
+ /**
+ * The "default" key.
+ *
+ * @since 6.1
+ */
+ public static final String CONFIG_KEY_DEFAULT = "default";
+
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java
index fda7a8152a..0de270261e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017, David Pursehouse <david.pursehouse@gmail.com> and others
+ * Copyright (C) 2017, 2022 David Pursehouse <david.pursehouse@gmail.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -10,7 +10,10 @@
package org.eclipse.jgit.transport;
+import java.util.Locale;
+
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.util.StringUtils;
/**
@@ -19,8 +22,9 @@ import org.eclipse.jgit.util.StringUtils;
* @since 4.9
*/
public class PushConfig {
+
/**
- * Config values for push.recurseSubmodules.
+ * Git config values for {@code push.recurseSubmodules}.
*/
public enum PushRecurseSubmodulesMode implements Config.ConfigEnum {
/**
@@ -59,4 +63,100 @@ public class PushConfig {
|| configValue.equalsIgnoreCase(s);
}
}
+
+ /**
+ * Git config values for {@code push.default}.
+ *
+ * @since 6.1
+ */
+ public enum PushDefault implements Config.ConfigEnum {
+
+ /**
+ * Do not push if there are no explicit refspecs.
+ */
+ NOTHING,
+
+ /**
+ * Push the current branch to an upstream branch of the same name.
+ */
+ CURRENT,
+
+ /**
+ * Push the current branch to an upstream branch determined by git
+ * config {@code branch.<currentBranch>.merge}.
+ */
+ UPSTREAM("tracking"), //$NON-NLS-1$
+
+ /**
+ * Like {@link #UPSTREAM}, but only if the upstream name is the same as
+ * the name of the current local branch.
+ */
+ SIMPLE,
+
+ /**
+ * Push all current local branches that match a configured push refspec
+ * of the remote configuration.
+ */
+ MATCHING;
+
+ private final String alias;
+
+ private PushDefault() {
+ alias = null;
+ }
+
+ private PushDefault(String alias) {
+ this.alias = alias;
+ }
+
+ @Override
+ public String toConfigValue() {
+ return name().toLowerCase(Locale.ROOT);
+ }
+
+ @Override
+ public boolean matchConfigValue(String in) {
+ return toConfigValue().equalsIgnoreCase(in)
+ || alias != null && alias.equalsIgnoreCase(in);
+ }
+ }
+
+ private final PushRecurseSubmodulesMode recurseSubmodules;
+
+ private final PushDefault pushDefault;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param config
+ * {@link Config} to fill the {@link PushConfig} from
+ * @since 6.1
+ */
+ public PushConfig(Config config) {
+ recurseSubmodules = config.getEnum(ConfigConstants.CONFIG_PUSH_SECTION,
+ null, ConfigConstants.CONFIG_KEY_RECURSE_SUBMODULES,
+ PushRecurseSubmodulesMode.NO);
+ pushDefault = config.getEnum(ConfigConstants.CONFIG_PUSH_SECTION, null,
+ ConfigConstants.CONFIG_KEY_DEFAULT, PushDefault.SIMPLE);
+ }
+
+ /**
+ * Retrieves the value of git config {@code push.recurseSubmodules}.
+ *
+ * @return the value
+ * @since 6.1
+ */
+ public PushRecurseSubmodulesMode getRecurseSubmodules() {
+ return recurseSubmodules;
+ }
+
+ /**
+ * Retrieves the value of git config {@code push.default}.
+ *
+ * @return the value
+ * @since 6.1
+ */
+ public PushDefault getPushDefault() {
+ return pushDefault;
+ }
}