Example usage for org.eclipse.jgit.lib Repository getConfig

List of usage examples for org.eclipse.jgit.lib Repository getConfig

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getConfig.

Prototype

@NonNull
public abstract StoredConfig getConfig();

Source Link

Document

Get the configuration of this repository.

Usage

From source file:org.jboss.as.test.manualmode.management.persistence.AbstractGitRepositoryTestCase.java

License:Apache License

protected Repository createRepository() throws IOException {
    Repository repo = new FileRepositoryBuilder().setWorkTree(getJbossServerBaseDir().toFile())
            .setGitDir(getDotGitDir().toFile()).setup().build();
    StoredConfig config = repo.getConfig();
    config.setString("remote", "empty", "url",
            "file://" + emptyRemoteRoot.resolve(Constants.DOT_GIT).toAbsolutePath().toString());
    config.save();/*from   ww w  .  j  av  a 2  s. c o m*/
    return repo;
}

From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java

License:Open Source License

/**
 *  Adds the remote config to given repository.
 *  //from  w w  w .  ja  v  a 2 s  .  co m
 * @param remoteName
 * @param uri
 * @param repository
 * @throws URISyntaxException
 * @throws MalformedURLException
 * @throws IOException
 */
public static void addRemoteConfig(String remoteName, URIish uri, Repository repository)
        throws URISyntaxException, MalformedURLException, IOException {
    StoredConfig config = repository.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);
    remoteConfig.update(config);
    config.save();
}

From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java

License:Open Source License

private static UserConfig getUserConfig(Repository repository) throws CoreException {
    Assert.isNotNull(repository, "Could not get user configuration. No repository provided.");

    if (repository.getConfig() == null) {
        throw new CoreException(new Status(IStatus.ERROR, FHPlugin.PLUGIN_ID,
                NLS.bind("no user configuration (author, committer) are present in repository \"{0}\"",
                        repository.toString())));
    }//from  w  w  w  .  j  av  a  2s. c  om
    return repository.getConfig().get(UserConfig.KEY);
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Gets the UserConfig from the given repository. The UserConfig of a repo
 * holds the default author and committer.
 * //from   w  ww  .ja v a 2 s  .  co m
 * @param repository
 *            the repository
 * @return the user configuration
 * @throws CoreException
 * 
 * @see PersonIdent(Repository)
 * @see CommittHelper#calculateCommitInfo
 */
private static UserConfig getUserConfig(Repository repository) throws CoreException {
    Assert.isLegal(repository != null, "Could not get user configuration. No repository provided.");

    if (repository.getConfig() == null) {
        throw new CoreException(createStatus(null,
                "no user configuration (author, committer) are present in repository \"{0}\"",
                repository.toString()));
    }
    return repository.getConfig().get(UserConfig.KEY);
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Returns all the remote configs from the given repository.
 * /*w ww. ja  va2s.c o  m*/
 * @param repository
 *            the repository to retrieve the remote configs of
 * @return the remote configs that are available on the repository
 * @throws CoreException
 */
public static List<RemoteConfig> getAllRemoteConfigs(Repository repository) throws CoreException {
    if (repository == null) {
        return Collections.emptyList();
    }
    try {
        return RemoteConfig.getAllRemoteConfigs(repository.getConfig());
    } catch (URISyntaxException e) {
        throw new CoreException(createStatus(e, "Could not get all remote repositories for repository \"{0}\"",
                repository.toString()));
    }
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Returns the name of the remote repository for the given branch. If
 * there's no current branch or no remote configured to it, the default
 * remote is returned ("origin").// ww  w .ja v a  2s .  c o m
 * 
 * @param branch
 *            the branch
 * @param repository
 *            the repository
 * @return the remote name
 */
private static String getRemoteName(String branch, Repository repository) {
    String remoteName = null;
    if (ObjectId.isId(branch)) {
        remoteName = Constants.DEFAULT_REMOTE_NAME;
    } else {
        remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch,
                ConfigConstants.CONFIG_REMOTE_SECTION);
        if (remoteName == null) {
            remoteName = Constants.DEFAULT_REMOTE_NAME;
        }
    }

    return remoteName;
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Adds the given uri of a remote repository to the given repository by the
 * given name./*w  ww. j  a va  2 s  .co  m*/
 * 
 * @param remoteName
 *            the name to use for the remote repository
 * @param uri
 *            the uri of the remote repository
 * @param repository
 *            the repository to add the remote to
 * @throws URISyntaxException
 *             the uRI syntax exception
 * @throws MalformedURLException
 *             the malformed url exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void addRemoteTo(String remoteName, URIish uri, Repository repository)
        throws URISyntaxException, MalformedURLException, IOException {
    StoredConfig config = repository.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);
    remoteConfig.update(config);
    config.save();
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Returns <code>true</code> if the given repo has commits that are not
 * contained withing the repo attached to it via the given remote. It is
 * ahead of the given remote config./*from   ww  w  .  j  a  v a 2s.  co m*/
 * This will work for non{@link BranchTrackingStatus#of(Repository, String)} will tell you if the
 * given branch is ahead of it's tracking branch. It only works with a
 * branch that is tracking another branch. 
 * 
 * @param repo
 *            the repo to check
 * @param remote
 *            the name of the remote to check against
 * @param monitor
 *            the monitor to report progress to
 * @return
 * @throws IOException
 * @throws InvocationTargetException
 * @throws URISyntaxException
 * 
 * @see BranchTrackingStatus#of
 */
public static boolean isAhead(Repository repo, String remote, IProgressMonitor monitor)
        throws IOException, InvocationTargetException, URISyntaxException {
    Assert.isLegal(remote != null);
    Assert.isLegal(repo != null);
    if (remote.equals(getRemote(repo.getBranch(), repo.getConfig()))) {
        BranchTrackingStatus status = BranchTrackingStatus.of(repo, repo.getBranch());
        if (status != null) {
            return status.getAheadCount() > 0;
        }
    }
    return isNonTrackingBranchAhead(repo, remote, monitor);
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

private static boolean isNonTrackingBranchAhead(Repository repo, String remote, IProgressMonitor monitor)
        throws URISyntaxException, InvocationTargetException, IOException {
    RemoteConfig remoteConfig = new RemoteConfig(repo.getConfig(), remote);
    FetchResult fetchResult = fetch(remoteConfig, repo, monitor);
    Ref ref = fetchResult.getAdvertisedRef(Constants.HEAD);
    if (ref == null) {
        return false;
    }// ww w . j  av a2  s.  co  m
    Ref currentBranchRef = repo.getRef(repo.getBranch());

    RevWalk walk = new RevWalk(repo);
    RevCommit localCommit = walk.parseCommit(currentBranchRef.getObjectId());
    RevCommit trackingCommit = walk.parseCommit(ref.getObjectId());
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(localCommit);
    walk.markStart(trackingCommit);
    RevCommit mergeBase = walk.next();
    walk.reset();
    walk.setRevFilter(RevFilter.ALL);
    int aheadCount = RevWalkUtils.count(walk, localCommit, mergeBase);

    return aheadCount > 0;
}

From source file:org.jboss.tools.openshift.egit.internal.test.EGitUtilsTest.java

License:Open Source License

@Test
public void canAddRemoteRepo() throws Exception {
    Repository repository = testRepository.getRepository();
    String remoteName = "redhat";
    String gitUri = "www.redhat.com";
    EGitUtils.addRemoteTo(remoteName, gitUri, repository);

    StoredConfig config = repository.getConfig();
    Set<String> subsections = config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
    assertEquals(1, subsections.size());
    assertTrue(subsections.contains(remoteName));
    assertEquals(gitUri, config.getString(ConfigConstants.CONFIG_REMOTE_SECTION, remoteName,
            ConfigConstants.CONFIG_KEY_URL));
}