SubmoduleConfig.java

  1. /*
  2.  * Copyright (C) 2017, David Pursehouse <david.pursehouse@gmail.com> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.lib;

  11. import org.eclipse.jgit.util.StringUtils;

  12. /**
  13.  * Submodule section of a Git configuration file.
  14.  *
  15.  * @since 4.7
  16.  */
  17. public class SubmoduleConfig {

  18.     /**
  19.      * Config values for submodule.[name].fetchRecurseSubmodules.
  20.      */
  21.     public enum FetchRecurseSubmodulesMode implements Config.ConfigEnum {
  22.         /** Unconditionally recurse into all populated submodules. */
  23.         YES("true"), //$NON-NLS-1$

  24.         /**
  25.          * Only recurse into a populated submodule when the superproject
  26.          * retrieves a commit that updates the submodule's reference to a commit
  27.          * that isn't already in the local submodule clone.
  28.          */
  29.         ON_DEMAND("on-demand"), //$NON-NLS-1$

  30.         /** Completely disable recursion. */
  31.         NO("false"); //$NON-NLS-1$

  32.         private final String configValue;

  33.         private FetchRecurseSubmodulesMode(String configValue) {
  34.             this.configValue = configValue;
  35.         }

  36.         @Override
  37.         public String toConfigValue() {
  38.             return configValue;
  39.         }

  40.         @Override
  41.         public boolean matchConfigValue(String s) {
  42.             if (StringUtils.isEmptyOrNull(s)) {
  43.                 return false;
  44.             }
  45.             s = s.replace('-', '_');
  46.             return name().equalsIgnoreCase(s)
  47.                     || configValue.equalsIgnoreCase(s);
  48.         }
  49.     }
  50. }