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

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

Introduction

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

Prototype

public abstract void load() throws IOException, ConfigInvalidException;

Source Link

Document

Load the configuration from the persistent store.

Usage

From source file:net.polydawn.mdm.commands.MdmRemoveCommand.java

License:Open Source License

public MdmExitMessage call() throws IOException, MdmException {
    try {/*from   ww  w  .j  av  a  2  s  .  c  o  m*/
        assertInRepoRoot();
    } catch (MdmExitMessage e) {
        return e;
    }

    // touch up args a tad.  tab completion in the terminal tends to suggest *almost* what you want, but with a trailing slash because it's a directory, and git doesn't like that slash.  so, we'll sand down that sharp corner a bit.
    String name = args.getString("name");
    if (name.endsWith("/"))
        name = name.substring(0, name.length() - 1);

    // load up config
    StoredConfig gitmodulesCfg = new FileBasedConfig(new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES),
            repo.getFS());
    try {
        gitmodulesCfg.load();
    } catch (ConfigInvalidException e) {
        throw new MdmExitInvalidConfig(Constants.DOT_GIT_MODULES);
    }

    // if there's no module there, we haven't got much to do
    try {
        MdmModuleDependency.load(repo, name, gitmodulesCfg);
    } catch (MdmModuleTypeException _) {
        return new MdmExitMessage(":I", "there is no mdm dependency by that name.");
    }

    // stage the remove and blow away the repo dirs
    try {
        new Git(repo).rm().setCached(true).addFilepattern(name).call();
    } catch (NoFilepatternException e) {
        throw new MajorBug(e); // why would an api throw exceptions like this *checked*?
    } catch (GitAPIException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    }
    IOForge.delete(new File(repo.getWorkTree(), name));
    IOForge.delete(new File(repo.getDirectory(), "modules/" + name)); // if this is one of the newer version of git (specifically, 1.7.8 or newer) that stores the submodule's data in the parent projects .git dir, clear that out forcefully as well.

    // blow away gitmodule config section
    gitmodulesCfg.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name);
    gitmodulesCfg.save();

    // commit the changes
    try {
        new Git(repo).add().addFilepattern(name).addFilepattern(Constants.DOT_GIT_MODULES).call();
    } catch (NoFilepatternException e) {
        throw new MajorBug(e); // why would an api throw exceptions like this *checked*?
    } catch (GitAPIException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    }
    try {
        new Git(repo).commit().setOnly(name).setOnly(Constants.DOT_GIT_MODULES)
                .setMessage("removing dependency on " + name + ".").call();
    } catch (NoHeadException e) {
        throw new MdmException("your repository is in an invalid state!", e);
    } catch (NoMessageException e) {
        throw new MajorBug(e); // why would an api throw exceptions like this *checked*?
    } catch (UnmergedPathsException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    } catch (ConcurrentRefUpdateException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    } catch (WrongRepositoryStateException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    } catch (GitAPIException e) {
        throw new MajorBug("an unrecognized problem occurred.  please file a bug report.", e);
    }

    // clear out local git config
    StoredConfig localConfig = repo.getConfig();
    localConfig.unsetSection(ConfigConstants.CONFIG_SUBMODULE_SECTION, name);
    localConfig.save();

    return new MdmExitMessage(":D", "removed dependency on " + name + "!");
}

From source file:org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog.java

License:Open Source License

private static StoredConfig loadUserScopedConfig() {
    StoredConfig c = SystemReader.getInstance().openUserConfig(null, FS.DETECTED);
    try {/* www . j  ava2s  . co  m*/
        c.load();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
    } catch (ConfigInvalidException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
    return c;
}

From source file:org.eclipse.egit.ui.internal.dialogs.BasicConfigurationDialog.java

License:Open Source License

private static StoredConfig loadRepoScopedConfig(Repository repo) {
    StoredConfig c = repo.getConfig();
    try {/*from  w  w  w .  j av a2 s  .c o  m*/
        c.load();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
    } catch (ConfigInvalidException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
    return c;
}

From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewRemoteHandlingTest.java

License:Open Source License

/**
 * Verify that remote configuration is shown correctly; also check error
 * node display/*from w  ww .  j a  v  a 2 s. c  o  m*/
 * 
 * @throws Exception
 */
@Test
public void testExpandRemotes() throws Exception {
    removeRemotesConfig(repositoryFile);
    refreshAndWait();
    SWTBotTree tree = getOrOpenView().bot().tree();
    SWTBotTreeItem remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
    assertEquals("Wrong number of remotes", 0, remotesItem.getNodes().size());
    StoredConfig cfg = lookupRepository(repositoryFile).getConfig();
    String remoteUri = "file:///" + remoteRepositoryFile.getPath();

    cfg.setString("remote", "test", "url", remoteUri);
    cfg.setString("remote", "test", "fetch", "somejunk");
    cfg.setString("remote", "test2", "url", remoteUri);
    cfg.setString("remote", "test2", "fetch", "somejunk");
    cfg.setString("remote", "test2", "pushurl", remoteUri);
    cfg.setString("remote", "test2", "push", "somejunk");
    cfg.setString("remote", "test3", "pushurl", "somejunk");
    cfg.setString("remote", "test3", "push", "somejunk");
    cfg.save();
    cfg.load();
    refreshAndWait();
    remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
    assertEquals("Wrong number of remotes", 3, remotesItem.getNodes().size());

    remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
    List<String> testnodes = remotesItem.getNode("test").expand().getNodes();
    assertTrue(testnodes.size() == 1);
    List<String> test2nodes = remotesItem.getNode("test2").expand().getNodes();
    assertTrue(test2nodes.size() == 2);
    // error node should be shown
    remotesItem.getNode("test3").expand().getNodes();
    assertTrue(remotesItem.getNode("test3").expand().getNodes().size() == 1);

    // test the properties view on remote
    remotesItem.getNode("test").select();
    ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("OpenPropertiesCommand"));
    waitInUI();
    assertEquals("org.eclipse.ui.views.PropertySheet", bot.activeView().getReference().getId());

    removeRemotesConfig(repositoryFile);
    refreshAndWait();
    remotesItem = myRepoViewUtil.getRemotesItem(tree, repositoryFile).expand();
    assertEquals("Wrong number of remotes", 0, remotesItem.getNodes().size());
}

From source file:org.flowerplatform.web.git.GitUtils.java

License:Open Source License

/**
 * This method must be used to set user configuration before running
 * some GIT commands that uses it.//  w w  w.  j a  v a  2s  .c  o  m
 * 
 * <p>
 * A lock/unlock on repository is done before/after the command is executed
 * because the configuration modifies the same file and this will not be
 * thread safe any more.
 */
public Object runGitCommandInUserRepoConfig(Repository repo, GitCommand<?> command) throws Exception {
    namedLockPool.lock(repo.getDirectory().getPath());

    try {
        StoredConfig c = repo.getConfig();
        c.load();
        User user = (User) CommunicationPlugin.tlCurrentPrincipal.get().getUser();

        c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, user.getName());
        c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL,
                user.getEmail());

        c.save();

        return command.call();
    } catch (Exception e) {
        throw e;
    } finally {
        namedLockPool.unlock(repo.getDirectory().getPath());
    }
}