Browse Source

Merge branch 'stable-4.10' into stable-4.11

* stable-4.10:
  SubmoduleValidator: Remove unused import of ConfigConstants
  SubmoduleValidator: Permit missing path or url

Change-Id: Id74c837d6cb728439ccbd6ade71936b493c09e08
Signed-off-by: Jonathan Nieder <jrn@google.com>
stable-4.11
Jonathan Nieder 6 years ago
parent
commit
eb41de5b25
  1. 28
      org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java

28
org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java

@ -42,13 +42,16 @@
*/ */
package org.eclipse.jgit.internal.submodule; package org.eclipse.jgit.internal.submodule;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PATH;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_URL;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_SUBMODULE_SECTION;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ConfigConstants;
/** /**
* Validations for the git submodule fields (name, path, uri). * Validations for the git submodule fields (name, path, uri).
@ -134,7 +137,6 @@ public class SubmoduleValidator {
*/ */
public static void assertValidSubmodulePath(String path) public static void assertValidSubmodulePath(String path)
throws SubmoduleValidationException { throws SubmoduleValidationException {
if (path.startsWith("-")) { //$NON-NLS-1$ if (path.startsWith("-")) { //$NON-NLS-1$
throw new SubmoduleValidationException( throw new SubmoduleValidationException(
MessageFormat.format( MessageFormat.format(
@ -154,19 +156,21 @@ public class SubmoduleValidator {
Config c = new Config(); Config c = new Config();
try { try {
c.fromText(gitModulesContents); c.fromText(gitModulesContents);
for (String subsection : c.getSubsections( for (String subsection :
ConfigConstants.CONFIG_SUBMODULE_SECTION)) { c.getSubsections(CONFIG_SUBMODULE_SECTION)) {
String url = c.getString(
ConfigConstants.CONFIG_SUBMODULE_SECTION,
subsection, ConfigConstants.CONFIG_KEY_URL);
assertValidSubmoduleUri(url);
assertValidSubmoduleName(subsection); assertValidSubmoduleName(subsection);
String url = c.getString(
CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_URL);
if (url != null) {
assertValidSubmoduleUri(url);
}
String path = c.getString( String path = c.getString(
ConfigConstants.CONFIG_SUBMODULE_SECTION, subsection, CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_PATH);
ConfigConstants.CONFIG_KEY_PATH); if (path != null) {
assertValidSubmodulePath(path); assertValidSubmodulePath(path);
}
} }
} catch (ConfigInvalidException e) { } catch (ConfigInvalidException e) {
throw new IOException( throw new IOException(

Loading…
Cancel
Save