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

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

Introduction

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

Prototype

public void setString(final String section, final String subsection, final String name, final String value) 

Source Link

Document

Add or modify a configuration value.

Usage

From source file:org.eclipse.egit.ui.test.TestUtil.java

License:Open Source License

public static void configureTestCommitterAsUser(Repository repository) {
    StoredConfig config = repository.getConfig();
    config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME,
            TestUtil.TESTCOMMITTER_NAME);
    config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL,
            TestUtil.TESTCOMMITTER_EMAIL);
}

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  ww  w .  ja 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.eclipse.mylyn.internal.github.core.pr.PullRequestUtils.java

License:Open Source License

/**
 * Configure pull request topic branch to use head remote
 *
 * @param repo/*w w  w .  j a va2s  .c  om*/
 * @param request
 * @throws IOException
 */
public static void configureTopicBranch(Repository repo, PullRequest request) throws IOException {
    String branch = getBranchName(request);
    String remote = request.getHead().getRepo().getOwner().getLogin();
    StoredConfig config = repo.getConfig();
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_MERGE,
            getHeadBranch(request));
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE, remote);
    config.save();
}

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

License:Open Source License

static void doConfigureClone(Git git, String user) throws IOException, CoreException {
    StoredConfig config = git.getRepository().getConfig();
    IOrionUserProfileNode userNode = UserServiceHelper.getDefault().getUserProfileService()
            .getUserProfileNode(user, true).getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    if (userNode.get(GitConstants.KEY_NAME, null) != null)
        config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME,
                userNode.get(GitConstants.KEY_NAME, null));
    if (userNode.get(GitConstants.KEY_MAIL, null) != null)
        config.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL,
                userNode.get(GitConstants.KEY_MAIL, null));
    config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false);
    config.save();/*from w  ww.  j  a  v a 2  s . co  m*/
}

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

License:Open Source License

@Test
public void testSyncSubmodule()
        throws IOException, SAXException, JSONException, CoreException, ConfigInvalidException {
    createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
    String workspaceId = getWorkspaceId(workspaceLocation);

    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project1"), null);
    JSONObject clone = clone(workspaceId, project);
    String contentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);
    String submoduleLocation = clone.getString(GitConstants.KEY_SUBMODULE);
    String location = clone.getString(ProtocolConstants.KEY_LOCATION);

    Repository repository = getRepositoryForContentLocation(contentLocation);
    File file = new File(repository.getWorkTree(), DOT_GIT_MODULES);
    assertFalse(file.exists());//ww w .  j  av a2s. com

    URIish uri = new URIish(gitDir.toURI().toURL());
    WebRequest request = postSubmoduleRequest(submoduleLocation, "test", uri.toString(), location);
    WebResponse response = webConversation.getResponse(request);

    file = new File(repository.getWorkTree(), DOT_GIT_MODULES);
    assertTrue(file.exists());

    assertNotNull(repository);

    StoredConfig repoConfig = repository.getConfig();
    String originalUrl = repoConfig.getString("submodule", "test", "url");
    repoConfig.setString("submodule", "test", "url", "value");
    repoConfig.save();
    assertEquals(repoConfig.getString("submodule", "test", "url"), "value");

    WebRequest reqSync = putSubmoduleRequest(submoduleLocation, "sync");
    WebResponse resSync = webConversation.getResponse(reqSync);

    repoConfig = repository.getConfig();
    assertEquals(repoConfig.getString("submodule", "test", "url"), originalUrl);

}

From source file:org.eclipse.recommenders.snipmatch.GitSnippetRepository.java

License:Open Source License

private void configureGit() throws IOException {
    Git git = Git.open(gitFile);/* w  w w .  j a v  a 2 s . co m*/
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", getRepositoryLocation());
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.setString("remote", "origin", "pushUrl", pushUrl);
    // prevents trust anchor errors when pulling from eclipse.org
    config.setBoolean("http", null, "sslVerify", false);
    config.save();
}

From source file:org.eclipse.recommenders.snipmatch.GitSnippetRepository.java

License:Open Source License

private void configureGitBranch(String remoteBranch) throws IOException {
    Git git = Git.open(gitFile);/* w ww.ja  v  a 2 s  .com*/
    StoredConfig config = git.getRepository().getConfig();
    String pushBranch = "HEAD:" + pushBranchPrefix + "/" + remoteBranch;
    config.setString("remote", "origin", "push", pushBranch);

    config.setString("branch", remoteBranch, "remote", "origin");
    String branch = "refs/heads/" + remoteBranch;
    config.setString("branch", remoteBranch, "merge", branch);
    config.save();
}

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

License:Open Source License

@RemoteInvocation
public boolean configBranch(ServiceInvocationContext context, List<PathFragment> path, GitRef upstreamBranch,
        RemoteConfig remote, boolean rebase) {
    try {/*from   w  ww  .j  a  va2s.co  m*/
        RefNode node = (RefNode) GenericTreeStatefulService.getNodeByPathFor(path, null);
        Repository repository = node.getRepository();
        StoredConfig config = repository.getConfig();

        Ref ref;
        if (node instanceof Ref) {
            ref = node.getRef();
        } else {
            // get remote branch
            String dst = Constants.R_REMOTES + remote.getName();
            String remoteRefName = dst + "/" + upstreamBranch.getShortName();
            ref = repository.getRef(remoteRefName);
            if (ref == null) { // doesn't exist, fetch it
                RefSpec refSpec = new RefSpec();
                refSpec = refSpec.setForceUpdate(true);
                refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName);

                new Git(repository).fetch().setRemote(new URIish(remote.getUri()).toPrivateString())
                        .setRefSpecs(refSpec).call();

                ref = repository.getRef(remoteRefName);
            }
        }

        String branchName = node.getRef().getName().substring(Constants.R_HEADS.length());
        if (upstreamBranch.getName().length() > 0) {
            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                    ConfigConstants.CONFIG_KEY_MERGE, upstreamBranch.getName());
        } else {
            config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE);
        }
        if (remote.getName().length() > 0) {
            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                    ConfigConstants.CONFIG_KEY_REMOTE, remote.getName());
        } else {
            config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE);
        }
        if (rebase) {
            config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                    ConfigConstants.CONFIG_KEY_REBASE, true);
        } else {
            config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE);
        }

        config.save();

        return true;
    } catch (Exception e) {
        logger.debug(CommonPlugin.getInstance().getMessage("error"), path, e);
        context.getCommunicationChannel().appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return false;
    }
}

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.//from   ww w.j  av a2s . c om
 * 
 * <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());
    }
}

From source file:org.flowerplatform.web.git.operation.CheckoutOperation.java

License:Open Source License

public boolean execute() {
    ProgressMonitor monitor = ProgressMonitor
            .create(GitPlugin.getInstance().getMessage("git.checkout.monitor.title"), channel);

    try {/*from  w  w  w.  j ava2s  .co  m*/
        monitor.beginTask(
                GitPlugin.getInstance().getMessage("git.checkout.monitor.message", new Object[] { name }), 4);
        monitor.setTaskName("Getting remote branch...");
        Git git = new Git(repository);
        Ref ref;
        if (node instanceof Ref) {
            ref = (Ref) node;
        } else {
            // get remote branch
            String dst = Constants.R_REMOTES + remote.getName();
            String remoteRefName = dst + "/" + upstreamBranch.getShortName();
            ref = repository.getRef(remoteRefName);
            if (ref == null) { // doesn't exist, fetch it
                RefSpec refSpec = new RefSpec();
                refSpec = refSpec.setForceUpdate(true);
                refSpec = refSpec.setSourceDestination(upstreamBranch.getName(), remoteRefName);

                git.fetch().setRemote(new URIish(remote.getUri()).toPrivateString()).setRefSpecs(refSpec)
                        .call();

                ref = repository.getRef(remoteRefName);
            }
        }
        monitor.worked(1);
        monitor.setTaskName("Creating local branch...");

        // create local branch
        git.branchCreate().setName(name).setStartPoint(ref.getName())
                .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();

        if (!(node instanceof Ref)) {
            // save upstream configuration
            StoredConfig config = repository.getConfig();

            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_MERGE,
                    upstreamBranch.getName());

            config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE,
                    remote.getName());

            if (rebase) {
                config.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, name,
                        ConfigConstants.CONFIG_KEY_REBASE, true);
            } else {
                config.unset(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REBASE);
            }
            config.save();
        }
        monitor.worked(1);
        monitor.setTaskName("Creating working directory");

        // create working directory for local branch
        File mainRepoFile = repository.getDirectory().getParentFile();
        File wdirFile = new File(mainRepoFile.getParentFile(), GitUtils.WORKING_DIRECTORY_PREFIX + name);
        if (wdirFile.exists()) {
            GitPlugin.getInstance().getUtils().delete(wdirFile);
        }
        GitPlugin.getInstance().getUtils().run_git_workdir_cmd(mainRepoFile.getAbsolutePath(),
                wdirFile.getAbsolutePath());
        monitor.worked(1);
        monitor.setTaskName("Checkout branch");

        // checkout local branch
        Repository wdirRepo = GitPlugin.getInstance().getUtils().getRepository(wdirFile);
        git = new Git(wdirRepo);

        CheckoutCommand cc = git.checkout().setName(name).setForce(true);
        cc.call();

        // show checkout result
        if (cc.getResult().getStatus() == CheckoutResult.Status.CONFLICTS)
            channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                    GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.title"),
                    GitPlugin.getInstance().getMessage("git.checkout.checkoutConflicts.message"),
                    cc.getResult().getConflictList().toString(),
                    DisplaySimpleMessageClientCommand.ICON_INFORMATION));

        else if (cc.getResult().getStatus() == CheckoutResult.Status.NONDELETED) {
            // double-check if the files are still there
            boolean show = false;
            List<String> pathList = cc.getResult().getUndeletedList();
            for (String path1 : pathList) {
                if (new File(wdirRepo.getWorkTree(), path1).exists()) {
                    show = true;
                    break;
                }
            }
            if (show) {
                channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                        GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.title"),
                        GitPlugin.getInstance().getMessage("git.checkout.nonDeletedFiles.message",
                                Repository.shortenRefName(name)),
                        cc.getResult().getUndeletedList().toString(),
                        DisplaySimpleMessageClientCommand.ICON_ERROR));
            }
        } else if (cc.getResult().getStatus() == CheckoutResult.Status.OK) {
            if (ObjectId.isId(wdirRepo.getFullBranch()))
                channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                        GitPlugin.getInstance().getMessage("git.checkout.detachedHead.title"),
                        GitPlugin.getInstance().getMessage("git.checkout.detachedHead.message"),
                        DisplaySimpleMessageClientCommand.ICON_ERROR));
        }
        monitor.worked(1);
        return true;
    } catch (Exception e) {
        channel.appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return false;
    } finally {
        monitor.done();
    }
}