Example usage for org.eclipse.jgit.lib StoredConfig getSections

List of usage examples for org.eclipse.jgit.lib StoredConfig getSections

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib StoredConfig getSections.

Prototype

public Set<String> getSections() 

Source Link

Document

Get the sections defined in this org.eclipse.jgit.lib.Config .

Usage

From source file:org.eclipse.che.git.impl.jgit.JGitConfigImpl.java

License:Open Source License

@Override
public List<String> getList() throws GitException {
    List<String> results = new ArrayList<>();
    // Iterate all sections and subsections, printing all values
    StoredConfig config = repository.getConfig();
    for (String section : config.getSections()) {
        for (String subsection : config.getSubsections(section)) {
            Set<String> names = config.getNames(section, subsection);
            addConfigValues(section, subsection, names, results);
        }//from   w  w  w .  ja  va2  s .c o  m
        Set<String> names = config.getNames(section);
        addConfigValues(section, null, names, results);
    }
    return results;
}

From source file:org.eclipse.egit.gitflow.GitFlowConfig.java

License:Open Source License

/**
 * @return git init done?//  ww w.  ja  v a 2  s  .c o  m
 * @throws IOException
 */
public boolean isInitialized() throws IOException {
    StoredConfig config = repository.getConfig();
    Set<String> sections = config.getSections();
    return sections.contains(GITFLOW_SECTION);
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoryPropertySource.java

License:Open Source License

public IPropertyDescriptor[] getPropertyDescriptors() {
    try {/*from  w  w  w  .j av a2s . c om*/
        userHomeConfig.load();
        repositoryConfig.load();
        effectiveConfig.load();
    } catch (IOException e) {
        showExceptionMessage(e);
    } catch (ConfigInvalidException e) {
        showExceptionMessage(e);
    }

    List<IPropertyDescriptor> resultList = new ArrayList<IPropertyDescriptor>();

    StoredConfig config;
    String category;
    String prefix;
    switch (getCurrentMode()) {
    case EFFECTIVE:
        prefix = EFFECTIVE_ID_PREFIX;
        category = UIText.RepositoryPropertySource_EffectiveConfigurationCategory;
        config = effectiveConfig;
        break;
    case REPO: {
        prefix = REPO_ID_PREFIX;
        String location = ""; //$NON-NLS-1$
        if (repositoryConfig instanceof FileBasedConfig) {
            location = ((FileBasedConfig) repositoryConfig).getFile().getAbsolutePath();
        }
        category = NLS.bind(UIText.RepositoryPropertySource_RepositoryConfigurationCategory, location);
        config = repositoryConfig;
        break;
    }
    case USER: {
        prefix = USER_ID_PREFIX;
        String location = userHomeConfig.getFile().getAbsolutePath();
        category = NLS.bind(UIText.RepositoryPropertySource_GlobalConfigurationCategory, location);
        config = userHomeConfig;
        break;
    }
    default:
        return new IPropertyDescriptor[0];
    }
    for (String key : config.getSections()) {
        for (String sectionItem : config.getNames(key)) {
            String sectionId = key + "." + sectionItem; //$NON-NLS-1$
            PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
            desc.setCategory(category);
            resultList.add(desc);
        }
        for (String sub : config.getSubsections(key)) {
            for (String sectionItem : config.getNames(key, sub)) {
                String sectionId = key + "." + sub + "." + sectionItem; //$NON-NLS-1$ //$NON-NLS-2$
                PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
                desc.setCategory(category);
                resultList.add(desc);
            }
        }
    }

    return resultList.toArray(new IPropertyDescriptor[0]);
}

From source file:org.eclipse.orion.server.git.servlets.GitSubmoduleHandlerV1.java

License:Open Source License

public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule)
        throws Exception {
    pathToSubmodule = pathToSubmodule.replace("\\", "/");
    StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo);
    gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
    gitSubmodulesConfig.save();// w  ww  . j  a  v a 2s.  com
    StoredConfig repositoryConfig = parentRepo.getConfig();
    repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule);
    repositoryConfig.save();
    Git git = Git.wrap(parentRepo);
    git.add().addFilepattern(DOT_GIT_MODULES).call();
    RmCommand rm = git.rm().addFilepattern(pathToSubmodule);
    if (gitSubmodulesConfig.getSections().size() == 0) {
        rm.addFilepattern(DOT_GIT_MODULES);
    }
    rm.call();
    FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE);
    FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE);
}