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:com.tenxdev.ovcs.command.InitCommand.java

License:Open Source License

private void initGitRepo(final Path workingDir, final String remoteUri, final String connectionString)
        throws OvcsException {
    try {/*w  w  w.  j  a  va  2  s  .c om*/
        System.out.println("Cloning git repo");
        Git.cloneRepository().setDirectory(workingDir.toFile()).setCloneAllBranches(true).setRemote("origin")
                .setURI(remoteUri).setProgressMonitor(new TextProgressMonitor()).call();
        final Git git = Git.open(workingDir.toFile());
        final StoredConfig config = git.getRepository().getConfig();
        config.setString("database", null, "connectionString", connectionString);
        config.save();
        git.checkout().setName("master").setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
    } catch (GitAPIException | IOException e) {
        throw new OvcsException("Unable to initialize Git repo: " + e.getMessage(), e);
    }
}

From source file:de.egore911.versioning.util.vcs.GitProvider.java

License:Open Source License

private InMemoryRepository initRepository() {
    DfsRepositoryDescription repoDesc = new DfsRepositoryDescription(
            "git - " + project.getName() + " on " + project.getVcsHost().getName());
    InMemoryRepository repo = new InMemoryRepository(repoDesc) {
        @Override/*from www .  j a v  a  2s .co  m*/
        public org.eclipse.jgit.util.FS getFS() {
            // Hack the InMemoryRepository to have a valid FS, eventhough it
            // does not have one. Otherwise the LsRemoteCommand will crash
            // with a NPE

            FS fs = super.getFS();
            if (fs == null) {
                fs = FS.DETECTED;
            }
            return fs;
        }
    };

    // Mock the configuration to contain the origin url
    StoredConfig config = repo.getConfig();
    config.setString("remote", "origin", "url", project.getCompleteVcsPath());
    return repo;
}

From source file:edu.wustl.lookingglass.community.CommunityRepository.java

License:Open Source License

private Git init() throws URISyntaxException, IOException, IllegalStateException, GitAPIException {
    assert !hasGitRepository(this.repoDir);

    Git git = Git.init().setDirectory(this.repoDir).call();

    StoredConfig config = git.getRepository().getConfig();
    config.setString("core", null, "ignorecase", "false"); // Be case sensitive explicitly to work on Mac
    config.setString("core", null, "filemode", "false"); // Ignore permission changes
    config.setString("core", null, "precomposeunicode", "true"); // Use the same Unicode form on all filesystems
    config.setString("push", null, "default", "simple");
    config.save();/*from  www  .  j a  v  a  2s.  com*/

    return git;
}

From source file:edu.wustl.lookingglass.community.CommunityRepository.java

License:Open Source License

private void addRemote(String newName, URL newURL) throws IOException, URISyntaxException {
    assert this.remoteName != null;
    assert this.remoteURL != null;

    boolean remoteExists = false;
    StoredConfig config = this.git.getRepository().getConfig();
    Set<String> remotes = config.getSubsections("remote");
    for (String oldName : remotes) {
        String oldURL = config.getString("remote", oldName, "url");
        if (newName.equals(oldName)) {
            remoteExists = true;// w  w w. j  av a 2 s .  c o  m
            if (newURL.toExternalForm().equals(oldURL)) {
                break;
            } else {
                Logger.warning("inconsistent remote url " + oldName + " : " + oldURL);
                config.setString("remote", oldName, "url", newURL.toExternalForm());
                config.save();
                break;
            }
        }
    }

    if (!remoteExists) {
        RemoteConfig remoteConfig = new RemoteConfig(config, this.remoteName);
        remoteConfig.addURI(new URIish(this.remoteURL));
        remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + this.remoteName + "/*"));
        remoteConfig.update(config);
        config.save();
    }
}

From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java

License:Apache License

public void setConfig() throws URISyntaxException, IOException, GitAPIException {
    StoredConfig config = gitRepository.getConfig();

    if (config.getString("remote", repoName, "url") == null
            || config.getString("remote", repoName, "url") != gitProxyUrl) {
        config.unset("remote", repoName, "url");
        RemoteConfig remoteConfig = new RemoteConfig(config, repoName);
        //cloud@94.75.243.141/proxyname.git
        //proxy<userid><applicationid>.git?
        //        String gitUrl = gitUser+"@"+gitProxyUrl+"/proxy"+this.userId+this.applicationId+".git";
        URIish uri = new URIish(gitProxyUrl);
        remoteConfig.addURI(uri);/*from   w  w  w  . j  ava 2  s .  co m*/
        config.unset("remote", repoName, "fetch");
        RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/" + repoName + "/*");
        remoteConfig.addFetchRefSpec(spec);
        remoteConfig.update(config);
    }

    if (config.getString("branch", "master", "remote") == null
            || config.getString("branch", "master", "remote") != repoName) {
        config.unset("branch", "master", "remote");
        config.setString("branch", "master", "remote", repoName);
    }
    if (config.getString("branch", "master", "merge") == null
            || config.getString("branch", "master", "merge") != "refs/heads/master") {
        config.unset("branch", "master", "merge");
        config.setString("branch", "master", "merge", "refs/heads/master");
    }
    config.save();
}

From source file:git_manager.tool.GitOperations.java

License:Open Source License

public void getConfigParameters() {
    StoredConfig config = git.getRepository().getConfig();
    String name = config.getString("user", null, "name");
    String email = config.getString("user", null, "email");
    if (name != null && email != null) {
        Object[] options = { "Yes", "No" };
        // TODO: Probably get this on the EDT instead
        int n = JOptionPane.showOptionDialog(new JFrame(),
                "The following global " + "user details have been detected:\n    Name: " + name
                        + "\n    Email: " + email + "\n\nContinue with these details?",
                "Who's there?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                options[1]);/*from  w ww .  j a  v  a2  s  .  c  o  m*/
        if (n == JOptionPane.YES_OPTION) {
            return;
        }
    }

    // TODO: Definitely make this nicer- better parsing and error handling, etc.
    // TODO: On the EDT with this too!
    // Adapted from http://www.edu4java.com/en/swing/swing3.html
    name = "";
    email = "";
    while (name.isEmpty() || email.isEmpty()) {
        JPanel configPanel = new JPanel();
        configPanel.setLayout(null);
        configPanel.setPreferredSize(new Dimension(300, 80));

        JLabel nameLabel = new JLabel("Name");
        nameLabel.setBounds(10, 10, 80, 25);
        configPanel.add(nameLabel);

        JTextField nameText = new JTextField(20);
        nameText.setBounds(100, 10, 160, 25);
        configPanel.add(nameText);
        nameText.setText(name);

        JLabel emailLabel = new JLabel("Email");
        emailLabel.setBounds(10, 40, 80, 25);
        configPanel.add(emailLabel);

        JTextField emailText = new JTextField(20);
        emailText.setBounds(100, 40, 160, 25);
        configPanel.add(emailText);
        emailText.setText(email);

        JOptionPane.showMessageDialog(new JFrame(), configPanel, "User details", JOptionPane.PLAIN_MESSAGE,
                null);

        name = nameText.getText();
        email = emailText.getText();

        if (name.isEmpty() || email.isEmpty()) {
            JOptionPane.showMessageDialog(new JFrame(),
                    "Neither the name nor the email address can be left blank", "Nopes",
                    JOptionPane.ERROR_MESSAGE, null);
        }
    }

    config.setString("user", null, "name", name);
    config.setString("user", null, "email", email);
    try {
        config.save();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:git_manager.tool.GitOperations.java

License:Open Source License

void storeRemote() {
    StoredConfig cofig = git.getRepository().getConfig();
    String configRemote = cofig.getString("remote", "origin", "url");
    //       String configUname = cofig.getString("remote", "origin", "url");

    if (configRemote == null || !configRemote.equals(remote)) {
        cofig.setString("remote", "origin", "url", remote);
        cofig.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
        try {//from   w w w  .  j  a va 2 s.  com
            cofig.save();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:git_manager.tool.GitOperations.java

License:Open Source License

void storeMergeBranch() {
    StoredConfig cofig = git.getRepository().getConfig();

    cofig.setString("branch", "master", "remote", "origin");
    cofig.setString("branch", "master", "merge", "refs/heads/master");
    try {/*  ww  w . j  av a 2s  . c om*/
        cofig.save();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gov.va.isaac.sync.git.SyncServiceGIT.java

License:Apache License

/**
 * @see gov.va.isaac.interfaces.sync.ProfileSyncI#relinkRemote(java.lang.String, java.lang.String, java.lang.String)
 *///from  ww w  .  ja  v  a2  s .  com
@Override
public void relinkRemote(String remoteAddress, String username, String password)
        throws IllegalArgumentException, IOException {
    log.debug("Configuring remote URL and fetch defaults to {}", remoteAddress);
    StoredConfig sc = getGit().getRepository().getConfig();
    sc.setString("remote", "origin", "url", remoteAddress);
    sc.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    sc.save();
}

From source file:io.fabric8.collector.git.GitHelpers.java

License:Apache License

public static void configureBranch(Git git, String branch, String origin, String remoteRepository) {
    // lets update the merge config
    if (!Strings.isNullOrBlank(branch)) {
        StoredConfig config = git.getRepository().getConfig();
        config.setString("branch", branch, "remote", origin);
        config.setString("branch", branch, "merge", "refs/heads/" + branch);

        config.setString("remote", origin, "url", remoteRepository);
        config.setString("remote", origin, "fetch", "+refs/heads/*:refs/remotes/" + origin + "/*");
        try {/*from   ww w  . ja  va  2s. c o m*/
            config.save();
        } catch (IOException e) {
            LOG.error("Failed to save the git configuration to " + git.getRepository().getDirectory()
                    + " with branch " + branch + " on " + origin + " remote repo: " + remoteRepository
                    + " due: " + e.getMessage() + ". This exception is ignored.", e);
        }
    }
}