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

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

Introduction

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

Prototype

public String getString(final String section, String subsection, final String name) 

Source Link

Document

Get string value or null if not found.

Usage

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 {//  w ww.j av a 2 s  .co m
            cofig.save();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:git_manager.tool.GitOperations.java

License:Open Source License

void getUnameandPass() {
    JTextField uName = new JTextField(15);
    JPasswordField pass = new JPasswordField(15);
    HintTextField remote = new HintTextField("https://github.com/uname/repo.git");

    JPanel panel = new JPanel(new GridLayout(0, 1));
    JPanel un = new JPanel();
    JPanel un2 = new JPanel();
    JPanel un3 = new JPanel();
    un.add(new JLabel("Username:   "));
    un.add(uName);//from w w w.  jav a2s . co  m
    panel.add(un);
    un2.add(new JLabel("Password:   "));
    un2.add(pass);
    panel.add(un2);
    un3.add(new JLabel("Repo:"));
    un3.add(remote);
    panel.add(un3);

    StoredConfig cofig = git.getRepository().getConfig();
    String remt = cofig.getString("remote", "origin", "url");

    if (remt != null && !remt.isEmpty()) {
        remote.setText(remt);
    }

    int result = JOptionPane.showConfirmDialog(null, panel, "Login Credentials", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    if (result == JOptionPane.OK_OPTION) {
        this.uName = uName.getText();
        this.pass = new String(pass.getPassword());
        this.remote = remote.getText();
    }
}

From source file:git_manager.tool.GitOperations.java

License:Open Source License

boolean getRemote() {
    HintTextField remote = new HintTextField("https://github.com/uname/repo.git");

    JPanel panel = new JPanel(new GridLayout(0, 1));
    JPanel un3 = new JPanel();
    un3.add(new JLabel("Repo:"));
    un3.add(remote);/*from  ww w . j  ava 2 s. c o m*/
    panel.add(un3);

    StoredConfig cofig = git.getRepository().getConfig();
    String remt = cofig.getString("remote", "origin", "url");

    if (remt != null && !remt.isEmpty()) {
        remote.setText(remt);
        remote.disableHint();
    }

    int result = JOptionPane.showConfirmDialog(null, panel, "Remote address", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    if (result == JOptionPane.OK_OPTION) {
        this.remote = remote.getText();
    }
    return (result == JOptionPane.OK_OPTION);
}

From source file:griffon.plugins.git.GitManager.java

License:Apache License

private PersonIdent personIdentFor(String key) {
    String name = (String) getConfigValue("git." + key + ".name", null);
    String email = (String) getConfigValue("git." + key + ".email", null);
    if (isBlank(name) || isBlank(email)) {
        try {//from   www  .  j a  v  a2  s.  c om
            StoredConfig storedConfig = git().getRepository().getConfig();
            storedConfig.load();
            name = storedConfig.getString("user", null, "name");
            email = storedConfig.getString("user", null, "email");
        } catch (IOException e) {
            // ignore
        } catch (ConfigInvalidException e) {
            // ignore
        }
    }

    if (!isBlank(name) && !isBlank(email)) {
        return new PersonIdent(name, email);
    }

    return null;
}

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

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent,
        UserDetails userDetails) {//w  w w  .j a  v  a2  s .  c om
    try {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", userDetails.getRemote(), "url");
        if (Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        PullCommand pull = git.pull();
        GitHelpers.configureCommand(pull, userDetails);
        pull.setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    }
}

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

License:Apache License

/**
 * Returns the remote git URL for the given branch
 *///from w  w  w .  j  a va 2  s. c  o m
public static String getRemoteURL(Git git, String branch) {
    StoredConfig config = git.getRepository().getConfig();
    return config.getString("branch", branch, "remote");
}

From source file:io.fabric8.forge.generator.pipeline.JenkinsPipelineLibrary.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent,
        UserDetails userDetails) {//from w  w  w. j a v  a 2 s. c o  m
    StopWatch watch = new StopWatch();
    try {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", remote, "url");
        if (io.fabric8.utils.Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (io.fabric8.utils.Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        // lets trash any failed changes
        LOG.debug("Stashing local changes to the repo");
        boolean hasHead = true;
        try {
            git.log().all().call();
            hasHead = git.getRepository().getAllRefs().containsKey("HEAD");
        } catch (NoHeadException e) {
            hasHead = false;
        }
        if (hasHead) {
            // lets stash any local changes just in case..
            try {
                git.stashCreate().setPerson(personIdent).setWorkingDirectoryMessage("Stash before a write")
                        .setRef("HEAD").call();
            } catch (Throwable e) {
                LOG.error("Failed to stash changes: " + e, e);
                Throwable cause = e.getCause();
                if (cause != null && cause != e) {
                    LOG.error("Cause: " + cause, cause);
                }
            }
        }

        //LOG.debug("Resetting the repo");
        //git.reset().setMode(ResetCommand.ResetType.HARD).call();

        LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        PullCommand pull = git.pull();
        GitUtils.configureCommand(pull, userDetails);
        pull.setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    } finally {
        LOG.debug("doPull took " + watch.taken());
    }
}

From source file:io.fabric8.forge.rest.git.RepositoryResource.java

License:Apache License

protected void configureBranch(Git git, String branch) {
    // lets update the merge config
    if (Strings.isNotBlank(branch)) {
        StoredConfig config = git.getRepository().getConfig();
        if (Strings.isNullOrBlank(config.getString("branch", branch, "remote"))
                || Strings.isNullOrBlank(config.getString("branch", branch, "merge"))) {
            config.setString("branch", branch, "remote", getRemote());
            config.setString("branch", branch, "merge", "refs/heads/" + branch);
            try {
                config.save();//from w w  w  .  jav a 2s .  c  o m
            } catch (IOException e) {
                LOG.error("Failed to save the git configuration to " + basedir + " with branch " + branch
                        + " on remote repo: " + remoteRepository + " due: " + e.getMessage()
                        + ". This exception is ignored.", e);
            }
        }
    }
}

From source file:io.fabric8.forge.rest.main.GitCommandCompletePostProcessor.java

License:Apache License

/**
 * Returns the remote git URL for the given branch
 *//* w w w .  ja  v  a 2 s .c  o m*/
protected String getRemoteURL(Git git, String branch) {
    StoredConfig config = git.getRepository().getConfig();
    return config.getString("branch", branch, "remote");
}

From source file:io.fabric8.forge.rest.main.ProjectFileSystem.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch) {
    try {//from w w  w  .  jav a  2  s.  c  o m
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", remote, "url");
        if (Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        // lets trash any failed changes
        LOG.info("Resetting the repo");
        git.reset().setMode(ResetCommand.ResetType.HARD).call();

        LOG.info("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        git.pull().setCredentialsProvider(cp).setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    }
}