Browse Source

Ensure .gitmodules is loaded when accessing submodule name

This problem occurred when calling SubmoduleWalk#getModuleName if the
first submodule processed has a name and a path which do not match
SubmoduleWalk#getModuleName returned the module path instead of the
module name. In order to fix this SubmoduleWalk#getModuleName needs to
ensure that the modules config is loaded.

Bug: 565776
Change-Id: I36ce1fbc64c4849f9d8e39864b825c6e28d344f8
Signed-off-by: John Dallaway <john@dallaway.org.uk>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v5.10.0.202011041322-m2
John Dallaway 3 years ago
parent
commit
f4b4dae2be

+ 1
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java View File

final CanonicalTreeParser p = new CanonicalTreeParser(); final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree()); p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) { try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
assertEquals(arbitraryName, gen.getModuleName());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());

+ 4
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java View File

import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
} }
} }
return results; return results;
} catch (ConfigInvalidException e) {
throw new InvalidConfigurationException(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} }

+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java View File

* *
* @since 4.10 * @since 4.10
* @return name * @return name
* @throws ConfigInvalidException
* @throws IOException
*/ */
public String getModuleName() {
public String getModuleName() throws IOException, ConfigInvalidException {
lazyLoadModulesConfig();
return getModuleName(path); return getModuleName(path);
} }



Loading…
Cancel
Save