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.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java

License:Open Source License

public Repository createGitRepository(Path path) {
    Repository toReturn;/*from w  w  w .  j a  va2s. c  o  m*/
    path = Paths.get(path.toAbsolutePath().toString(), GIT_ROOT);
    try {
        toReturn = FileRepositoryBuilder.create(path.toFile());
        toReturn.create();

        // Get git configuration
        StoredConfig config = toReturn.getConfig();
        // Set compression level (core.compression)
        config.setInt(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_COMPRESSION,
                CONFIG_PARAMETER_COMPRESSION_DEFAULT);
        // Set big file threshold (core.bigFileThreshold)
        config.setString(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_BIG_FILE_THRESHOLD,
                CONFIG_PARAMETER_BIG_FILE_THRESHOLD_DEFAULT);
        // Save configuration changes
        config.save();
    } catch (IOException e) {
        logger.error("Error while creating repository for site with path" + path.toString(), e);
        toReturn = null;
    }

    return toReturn;
}

From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

public void clone(CloneRequest request) throws GitException, UnauthorizedException {
    String remoteUri;//from   ww  w . ja v a2  s.  com
    boolean removeIfFailed = false;
    try {
        if (request.getRemoteName() == null) {
            request.setRemoteName(Constants.DEFAULT_REMOTE_NAME);
        }
        if (request.getWorkingDir() == null) {
            request.setWorkingDir(repository.getWorkTree().getCanonicalPath());
        }

        // If clone fails and the .git folder didn't exist we want to remove it.
        // We have to do this here because the clone command doesn't revert its own changes in case of failure.
        removeIfFailed = !repository.getDirectory().exists();

        remoteUri = request.getRemoteUri();
        CloneCommand cloneCommand = Git.cloneRepository().setDirectory(new File(request.getWorkingDir()))
                .setRemote(request.getRemoteName()).setURI(remoteUri);
        if (request.getBranchesToFetch().isEmpty()) {
            cloneCommand.setCloneAllBranches(true);
        } else {
            cloneCommand.setBranchesToClone(request.getBranchesToFetch());
        }

        executeRemoteCommand(remoteUri, cloneCommand);

        StoredConfig repositoryConfig = getRepository().getConfig();
        GitUser gitUser = getUser();
        if (gitUser != null) {
            repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null,
                    ConfigConstants.CONFIG_KEY_NAME, gitUser.getName());
            repositoryConfig.setString(ConfigConstants.CONFIG_USER_SECTION, null,
                    ConfigConstants.CONFIG_KEY_EMAIL, gitUser.getEmail());
        }
        repositoryConfig.save();
    } catch (IOException | GitAPIException exception) {
        // Delete .git directory in case it was created
        if (removeIfFailed) {
            deleteRepositoryFolder();
        }
        throw new GitException(exception.getMessage(), exception);
    }
}

From source file:org.eclipse.egit.core.internal.ProjectReferenceImporterTest.java

License:Open Source License

private static void addRemote(Repository repository, String name, URIish url) throws IOException {
    StoredConfig config = repository.getConfig();
    config.setString("remote", name, "url", url.toString());
    config.save();/*from  w  w w.  java  2  s .  c  o m*/
}

From source file:org.eclipse.egit.gitflow.GitFlowConfig.java

License:Open Source License

/**
 * Set prefix in .git/config/*from w ww  .  j  a v  a  2  s .c  o  m*/
 *
 * @param prefixName
 * @param value
 */
public void setPrefix(String prefixName, String value) {
    StoredConfig config = repository.getConfig();
    config.setString(GITFLOW_SECTION, PREFIX_SECTION, prefixName, value);
}

From source file:org.eclipse.egit.gitflow.GitFlowConfig.java

License:Open Source License

/**
 * Set branchName in .git/config/* ww w  .  j  a v  a 2  s  .co m*/
 *
 * @param branchName
 * @param value
 */
public void setBranch(String branchName, String value) {
    StoredConfig config = repository.getConfig();
    config.setString(GITFLOW_SECTION, BRANCH_SECTION, branchName, value);
}

From source file:org.eclipse.egit.gitflow.GitFlowConfig.java

License:Open Source License

private void setBranchValue(String featureName, String value, String mergeKey) throws IOException {
    StoredConfig config = repository.getConfig();
    config.setString(BRANCH_SECTION, featureName, mergeKey, value);
    config.save();//from  w w  w.  j a  v a  2 s .c  o  m
}

From source file:org.eclipse.egit.ui.httpauth.PushTest.java

License:Open Source License

private void configurePush() throws Exception {
    StoredConfig config = localRepository.getConfig();
    config.setString("remote", "push", "pushurl", remoteRepository.getUri());
    config.setString("remote", "push", "push", "+refs/heads/*:refs/heads/*");
    config.save();//  www .  ja va2 s .c  o  m
}

From source file:org.eclipse.egit.ui.internal.pull.PullWizard.java

License:Open Source License

private void configureUpstream() throws IOException {
    String fullBranch = this.repository.getFullBranch();
    if (fullBranch == null || !fullBranch.startsWith(Constants.R_HEADS)) {
        // Don't configure upstream for detached HEAD
        return;/*from ww w  .j  a v  a 2s  . c om*/
    }
    String remoteName = this.page.getRemoteConfig().getName();
    String fullRemoteBranchName = this.page.getFullRemoteReference();

    String localBranchName = this.repository.getBranch();
    StoredConfig config = repository.getConfig();
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE,
            remoteName);
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE,
            fullRemoteBranchName);
    BranchRebaseMode rebaseMode = this.page.getUpstreamConfig();
    if (rebaseMode != null) {
        config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
                ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
    }

    config.save();
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizard.java

License:Open Source License

private void configureUpstream() throws IOException {
    if (this.ref == null) {
        // Don't configure upstream for detached HEAD
        return;//from  ww w .  j a  v a  2 s  . co m
    }
    String remoteName = getRemoteName();
    String fullRemoteBranchName = pushBranchPage.getFullRemoteReference();
    String localBranchName = Repository.shortenRefName(this.ref.getName());

    StoredConfig config = repository.getConfig();
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_REMOTE,
            remoteName);
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName, ConfigConstants.CONFIG_KEY_MERGE,
            fullRemoteBranchName);
    BranchRebaseMode rebaseMode = pushBranchPage.getUpstreamConfig();
    if (rebaseMode != null) {
        config.setEnum(ConfigConstants.CONFIG_BRANCH_SECTION, localBranchName,
                ConfigConstants.CONFIG_KEY_REBASE, rebaseMode);
    }

    config.save();
}

From source file:org.eclipse.egit.ui.internal.repository.tree.command.DeleteFetchCommand.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    FetchNode node = getSelectedNodes(event).get(0);
    RemoteNode remote = (RemoteNode) node.getParent();

    StoredConfig config = node.getRepository().getConfig();
    String fetchUrl = config.getString(REMOTE, remote.getObject(), URL);
    config.unset(REMOTE, remote.getObject(), FETCH);
    config.unset(REMOTE, remote.getObject(), URL);
    // the push URL may still be needed for fetch
    if (fetchUrl != null) {
        boolean hasPush = config.getStringList(REMOTE, remote.getObject(), PUSH).length > 0;
        if (hasPush) {
            String[] pushurls = config.getStringList(REMOTE, remote.getObject(), PUSHURL);
            // if there are not specific push urls,
            // copy the former fetch url into push url
            if (pushurls.length == 0)
                config.setString(REMOTE, remote.getObject(), PUSHURL, fetchUrl);
        }//ww  w.  j a v  a 2 s .  co m
    }

    try {
        config.save();
    } catch (IOException e1) {
        Activator.handleError(e1.getMessage(), e1, true);
    }

    return null;
}