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

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

Introduction

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

Prototype

public abstract void save() throws IOException;

Source Link

Document

Save the configuration to the persistent store.

Usage

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Admin })
@Override//w  w w  .j a  v  a2s  . com
public void createEmptyRepository(ScmRepository repository) {
    File hostedDir = repositoryProvider.getTenantHostedBaseDir();
    File gitDir = new File(hostedDir, repository.getName());
    File descriptionFile = new File(gitDir, "description");
    gitDir.mkdirs();
    try {
        FileRepository repo = new FileRepository(gitDir);
        repo.create();
        descriptionFile.createNewFile();
        writeToDescription(descriptionFile, repository.getDescription());
        StoredConfig config = repo.getConfig();
        config.setBoolean("receive", null, "denynonfastforwards", true);
        config.save();
        repo.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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  ww .  j ava 2s.c o  m
        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.blizzy.documentr.repository.ProjectRepositoryManager.java

License:Open Source License

public void importSampleContents() throws IOException, GitAPIException {
    // TODO: synchronization is not quite correct here, but should be okay in this edge case
    if (listBranches().isEmpty()) {
        ILock lock = lockManager.lockAll();
        List<String> branches;
        try {//from   w w  w .  ja v a2 s.co  m
            File gitDir = new File(centralRepoDir, ".git"); //$NON-NLS-1$
            FileUtils.forceDelete(gitDir);

            Git.cloneRepository().setURI(DocumentrConstants.SAMPLE_REPO_URL).setDirectory(gitDir).setBare(true)
                    .call();

            Repository centralRepo = null;
            File centralRepoGitDir;
            try {
                centralRepo = getCentralRepositoryInternal(true);
                centralRepoGitDir = centralRepo.getDirectory();
                StoredConfig config = centralRepo.getConfig();
                config.unsetSection("remote", "origin"); //$NON-NLS-1$ //$NON-NLS-2$
                config.unsetSection("branch", "master"); //$NON-NLS-1$ //$NON-NLS-2$
                config.save();
            } finally {
                RepositoryUtil.closeQuietly(centralRepo);
            }

            branches = listBranches();
            for (String branchName : branches) {
                File repoDir = new File(reposDir, branchName);
                Repository repo = null;
                try {
                    repo = Git.cloneRepository().setURI(centralRepoGitDir.toURI().toString())
                            .setDirectory(repoDir).call().getRepository();

                    Git git = Git.wrap(repo);
                    RefSpec refSpec = new RefSpec(
                            "refs/heads/" + branchName + ":refs/remotes/origin/" + branchName); //$NON-NLS-1$ //$NON-NLS-2$
                    git.fetch().setRemote("origin").setRefSpecs(refSpec).call(); //$NON-NLS-1$
                    git.branchCreate().setName(branchName).setStartPoint("origin/" + branchName).call(); //$NON-NLS-1$
                    git.checkout().setName(branchName).call();
                } finally {
                    RepositoryUtil.closeQuietly(repo);
                }
            }
        } finally {
            lockManager.unlock(lock);
        }

        for (String branch : branches) {
            eventBus.post(new BranchCreatedEvent(projectName, branch));
        }
    }
}

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();

    return git;/*from  ww w  .  j  a va  2 s .  c  om*/
}

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 a va 2s .  co 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  ava2s.  c o  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:ezbake.deployer.publishers.openShift.RhcApplication.java

License:Apache License

/**
 * Sets the git repository object.  Probably not useful but here for Java Bean completeness
 *
 * @param gitRepo - git repository to set it to
 *//*from   w  w w . java  2  s. co  m*/
public void setGitRepo(Git gitRepo) throws DeploymentException {
    this.gitRepo = gitRepo;

    try {
        StoredConfig config = gitRepo.getRepository().getConfig();
        config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true);
        config.save();
    } catch (IOException e) {
        log.error("There was an error saving the  git configuration to disk", e);
        throw new DeploymentException("Could not save git configuration: " + e.getMessage());
    }
}

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 w w  .j  ava  2  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 {// w  w  w. jav  a 2  s  . c o m
            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.ja va 2s  .  c o  m*/
        cofig.save();
    } catch (IOException e) {
        e.printStackTrace();
    }
}