From d3eaf1007b42048bd507ee5634af571863b8e21d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 7 Oct 2018 21:55:52 +0000 Subject: [PATCH 1/2] SubmoduleValidator: Permit missing path or url A .gitmodules file can include a submodule without a path to configure the URL for a submodule that is only present on other branches. A .gitmodules file can include a submodule with no URL and no path to reserve the name for a submodule that existed in earlier history but is not available from any URL any more. "git fsck" permits both of these cases. Permit them in JGit as well (instead of throwing NullPointerException). Change-Id: I3b442639ad79ea7a59227f96406a12e62d3573ae Reported-by: David Pursehouse Signed-off-by: Jonathan Nieder --- .../submodule/SubmoduleValidator.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java index d4bba2d0d..5f405044c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java @@ -42,6 +42,10 @@ */ 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.text.MessageFormat; @@ -134,7 +138,6 @@ public class SubmoduleValidator { */ public static void assertValidSubmodulePath(String path) throws SubmoduleValidationException { - if (path.startsWith("-")) { //$NON-NLS-1$ throw new SubmoduleValidationException( MessageFormat.format( @@ -154,19 +157,21 @@ public class SubmoduleValidator { Config c = new Config(); try { c.fromText(gitModulesContents); - for (String subsection : c.getSubsections( - ConfigConstants.CONFIG_SUBMODULE_SECTION)) { - String url = c.getString( - ConfigConstants.CONFIG_SUBMODULE_SECTION, - subsection, ConfigConstants.CONFIG_KEY_URL); - assertValidSubmoduleUri(url); - + for (String subsection : + c.getSubsections(CONFIG_SUBMODULE_SECTION)) { assertValidSubmoduleName(subsection); + String url = c.getString( + CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_URL); + if (url != null) { + assertValidSubmoduleUri(url); + } + String path = c.getString( - ConfigConstants.CONFIG_SUBMODULE_SECTION, subsection, - ConfigConstants.CONFIG_KEY_PATH); - assertValidSubmodulePath(path); + CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_PATH); + if (path != null) { + assertValidSubmodulePath(path); + } } } catch (ConfigInvalidException e) { throw new IOException( From 26e7a74601f6e6594c9378033b8c700854fe0f6a Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 9 Oct 2018 08:29:26 +0900 Subject: [PATCH 2/2] SubmoduleValidator: Remove unused import of ConfigConstants Change-Id: I6afe5690bf9d1f1f4d414aa618daefc8b48d217e Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/internal/submodule/SubmoduleValidator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java index 5f405044c..365163157 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java @@ -52,7 +52,6 @@ import java.text.MessageFormat; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Config; -import org.eclipse.jgit.lib.ConfigConstants; /** * Validations for the git submodule fields (name, path, uri).