List of usage examples for org.eclipse.jgit.submodule SubmoduleWalk setModulesConfig
public SubmoduleWalk setModulesConfig(Config config)
From source file:net.polydawn.mdm.MdmModuleSet.java
License:Open Source License
public MdmModuleSet(Repository repo) throws IOException, ConfigInvalidException { gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS()); gitmodulesCfg.load();/*from w ww . ja v a 2 s.c o m*/ /* * To maximize similarity with how the `git submodule` command behaves, we treat the SubmoduleWalk as canonical and the content of the .gitmodules file as tertiary. * However, that may change. There's a lot about MdmModule that doesn't work without a .gitmodules entry anyway, so if it's faster to start from that list, we might as well. */ SubmoduleWalk mw = new SubmoduleWalk(repo); mw.setModulesConfig(gitmodulesCfg); SubmoduleWalk generator = SubmoduleWalk.forIndex(repo); while (generator.next()) { try { // get the handle. which we presume to be rather like the path, but git config always uses forward slashes. // (the MdmModule constructor will also enforce this, but here we have to walk config ourselves before we get that far.) String handle = (File.separatorChar != '/') ? generator.getPath().replace(File.separatorChar, '/') : generator.getPath(); // get submodule.[handle].mdm config value from gitmodules config file String type_configured_string = gitmodulesCfg.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, handle, MdmConfigConstants.Module.MODULE_TYPE.toString()); MdmModuleType type_configured = MdmModuleType.fromString(type_configured_string); // if the submodule.[handle].mdm config value was unrecognized or missing, ignore; it's not ours. if (type_configured == null) continue; // load whichever type of mdm module it is switch (type_configured) { case DEPENDENCY: MdmModuleDependency modDep = MdmModuleDependency.load(repo, generator, gitmodulesCfg); dependencyModules.put(modDep.getHandle(), modDep); allModules.put(modDep.getHandle(), modDep); break; case RELEASES: MdmModuleRelease modRel = MdmModuleRelease.load(repo, generator, gitmodulesCfg); releasesModules.put(modRel.getHandle(), modRel); allModules.put(modRel.getHandle(), modRel); break; } } catch (MdmModuleTypeException e) { throw new MajorBug(e); } catch (MdmRepositoryNonexistant e) { throw e; } catch (MdmRepositoryIOException e) { throw e; } } }