Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushConfig.java104
1 files changed, 102 insertions, 2 deletions
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..c8774d546a 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;
+ }
}

Back to the top