Browse Source

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 <david.pursehouse@gmail.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
tags/v4.7.6.201810191618-r
Jonathan Nieder 5 years ago
parent
commit
d3eaf1007b

+ 16
- 11
org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java View File

*/ */
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;


*/ */
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(
Config c = new Config(); Config c = new Config();
try { try {
c.fromText(gitModulesContents); 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); 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,
ConfigConstants.CONFIG_KEY_PATH);
assertValidSubmodulePath(path);
CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_PATH);
if (path != null) {
assertValidSubmodulePath(path);
}
} }
} catch (ConfigInvalidException e) { } catch (ConfigInvalidException e) {
throw new IOException( throw new IOException(

Loading…
Cancel
Save