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:com.microsoft.gittf.core.config.GitTFConfiguration.java

License:Open Source License

public static String getPassword(final Repository repository) {
    /*/*from   w ww .jav a 2  s.  co m*/
     * The repository could be not initialized yet, in this case we'll get
     * the value (if any) from a global config file
     */
    return repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.PASSWORD);

}

From source file:com.microsoft.gittf.core.config.GitTFConfiguration.java

License:Open Source License

/**
 * Saves this configuration to the given git repository's configuration.
 * /*from ww  w  .  j a v a2s .c  o  m*/
 * @param repository
 *        The {@link Repository} to save this configuration to (must not be
 *        <code>null</code>)
 * @return <code>true</code> if the configuration was saved successfully
 */
public boolean saveTo(final Repository repository) {
    Check.notNull(repository, "repository"); //$NON-NLS-1$

    repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.SERVER_COLLECTION_URI,
            serverURI.toASCIIString());

    repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.SERVER_PATH, tfsPath);

    if (isLocallyDefined(ConfigurationConstants.DEPTH)) {
        repository.getConfig().setInt(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.DEPTH,
                deep ? Integer.MAX_VALUE : 1);
    }

    if (isLocallyDefined(ConfigurationConstants.FILE_FORMAT_VERSION)) {
        repository.getConfig().setInt(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.FILE_FORMAT_VERSION,
                GitTFConstants.GIT_TF_CURRENT_FORMAT_VERSION);
    }

    if (isLocallyDefined(ConfigurationConstants.TAG)) {
        repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TAG, tag);
    }

    if (isLocallyDefined(ConfigurationConstants.INCLUDE_METADATA)) {
        repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.INCLUDE_METADATA,
                includeMetaData);
    }

    if (isLocallyDefined(ConfigurationConstants.KEEP_AUTHOR)) {
        repository.getConfig().setBoolean(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.KEEP_AUTHOR, keepAuthor);
    }

    if (isLocallyDefined(ConfigurationConstants.USER_MAP)) {
        if (!StringUtil.isNullOrEmpty(userMap)) {
            repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
                    ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.USER_MAP, userMap);
        } else {
            repository.getConfig().unset(ConfigurationConstants.CONFIGURATION_SECTION,
                    ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.USER_MAP);
        }
    }

    if (isLocallyDefined(ConfigurationConstants.GATED_BUILD_DEFINITION)
            && !StringUtil.isNullOrEmpty(buildDefinition)) {
        repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.GATED_BUILD_DEFINITION,
                buildDefinition);
    }

    if (isLocallyDefined(ConfigurationConstants.USERNAME)) {
        repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.USERNAME, username);
    }

    if (isLocallyDefined(ConfigurationConstants.PASSWORD)) {
        repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.PASSWORD, password);
    }

    if (isLocallyDefined(ConfigurationConstants.TEMP_DIRECTORY) && !StringUtil.isNullOrEmpty(tempDirectory)) {
        repository.getConfig().setString(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TEMP_DIRECTORY,
                tempDirectory);
    }

    repository.getConfig().setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
            ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);

    try {
        repository.getConfig().save();
    } catch (IOException e) {
        log.error("Could not save server configuration to repository", e); //$NON-NLS-1$
        return false;
    }

    return true;
}

From source file:com.microsoft.gittf.core.config.GitTFConfiguration.java

License:Open Source License

/**
 * Loads the git-tf configuration from the given git repository.
 * //from  w  w  w . jav  a  2  s  . com
 * @param repository
 *        The {@link Repository} to load git-tf configuration data from
 *        (must not be <code>null</code>)
 * @return A new {@link GitTFConfiguration}, or <code>null</code> if the git
 *         repository does not contain a valid git-tf configuration
 */
public static GitTFConfiguration loadFrom(final Repository repository) {
    Check.notNull(repository, "repository"); //$NON-NLS-1$

    final String projectCollection = repository.getConfig().getString(
            ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION,
            ConfigurationConstants.SERVER_COLLECTION_URI);

    final String tfsPath = repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.SERVER_PATH);

    final String username = repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.USERNAME);

    final String password = repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION, ConfigurationConstants.PASSWORD);

    final int depth = repository.getConfig().getInt(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.DEPTH,
            GitTFConstants.GIT_TF_SHALLOW_DEPTH);

    final boolean tag = repository.getConfig().getBoolean(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TAG, true);

    final boolean includeMetaData = repository.getConfig().getBoolean(
            ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.GENERAL_SUBSECTION,
            ConfigurationConstants.INCLUDE_METADATA, GitTFConstants.GIT_TF_DEFAULT_INCLUDE_METADATA);

    final int fileFormatVersion = repository.getConfig().getInt(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.FILE_FORMAT_VERSION, 0);

    final String buildDefinition = repository.getConfig().getString(
            ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.SERVER_SUBSECTION,
            ConfigurationConstants.GATED_BUILD_DEFINITION);

    final String tempDirectory = repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.TEMP_DIRECTORY);

    final boolean keepAuthor = repository.getConfig().getBoolean(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.KEEP_AUTHOR,
            GitTFConstants.GIT_TF_DEFAULT_KEEP_AUTHOR);

    final String userMap = repository.getConfig().getString(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.USER_MAP);

    if (projectCollection == null) {
        log.error("No project collection configuration in repository"); //$NON-NLS-1$
        return null;
    }

    if (tfsPath == null) {
        log.error("No TFS server path configuration in repository"); //$NON-NLS-1$
        return null;
    }

    URI serverURI;

    try {
        serverURI = new URI(projectCollection);
    } catch (URISyntaxException e) {
        log.error("TFS project collection URI is malformed", e); //$NON-NLS-1$
        return null;
    }

    final String[] sectionNames = new String[] { ConfigurationConstants.GENERAL_SUBSECTION,
            ConfigurationConstants.SERVER_SUBSECTION };
    final Map<String, Boolean> isDefined = new HashMap<String, Boolean>();

    for (final String sectionName : sectionNames) {
        final Set<String> definedNames = repository.getConfig()
                .getNames(ConfigurationConstants.CONFIGURATION_SECTION, sectionName);

        for (final String name : definedNames) {
            isDefined.put(name, true);
        }
    }

    return new GitTFConfiguration(serverURI, tfsPath, username, password,
            depth > GitTFConstants.GIT_TF_SHALLOW_DEPTH, tag, includeMetaData, fileFormatVersion,
            buildDefinition, tempDirectory, keepAuthor, userMap, isDefined);
}

From source file:com.microsoft.gittf.core.config.GitTFConfiguration.java

License:Open Source License

/**
 * Removes the git-tf configuration data from a git repository.
 * //from w  ww .j a v  a2  s  .  c  o m
 * @param repository
 *        The {@link Repository} to remove configuration from (must not be
 *        <code>null</code>)
 */
public static void removeFrom(final Repository repository) {
    Check.notNull(repository, "repository"); //$NON-NLS-1$

    repository.getConfig().unsetSection(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.SERVER_SUBSECTION);

    repository.getConfig().unsetSection(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION);
}

From source file:com.microsoft.gittf.core.tasks.CloneTaskTest.java

License:Open Source License

@Test
public void testShallowCloneFilesAndFolders() throws Exception {
    URI projectCollectionURI = new URI("http://fakeCollection:8080/tfs/DefaultCollection"); //$NON-NLS-1$
    String tfsPath = "$/project"; //$NON-NLS-1$
    String gitRepositoryPath = Util.getRepositoryFile(getName()).getAbsolutePath();

    final MockVersionControlService mockVersionControlService = new MockVersionControlService();

    mockVersionControlService.AddFile("$/project/folder/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file0.txt", 1); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 2); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file2.txt", 3); //$NON-NLS-1$

    Calendar date = Calendar.getInstance();
    date.set(2012, 11, 12, 18, 15);//  ww w.j ava  2 s .co  m

    MockChangesetProperties changesetProperties = new MockChangesetProperties("ownerDisplayName", //$NON-NLS-1$
            "ownerName", //$NON-NLS-1$
            "committerDisplayName", //$NON-NLS-1$
            "committerName", //$NON-NLS-1$
            "comment", //$NON-NLS-1$
            date);
    mockVersionControlService.updateChangesetInformation(changesetProperties, 3);

    final Repository repository = RepositoryUtil.createNewRepository(gitRepositoryPath, false);
    final boolean defaultDeep = repository.getConfig().getInt(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.DEPTH,
            GitTFConstants.GIT_TF_SHALLOW_DEPTH) > 1;

    CloneTask cloneTask = new CloneTask(projectCollectionURI, mockVersionControlService, tfsPath, repository);
    TaskStatus cloneTaskStatus = cloneTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(cloneTaskStatus.isOK());

    // Load Git Repo
    Git git = new Git(repository);
    git.checkout().setName("master").call(); //$NON-NLS-1$

    // Verify Changeset 1
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file0.txt"), //$NON-NLS-1$
            "$/project/folder/file0.txt", //$NON-NLS-1$
            1));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file0.txt"), //$NON-NLS-1$
            "$/project/folder2/file0.txt", //$NON-NLS-1$
            1));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file0.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file0.txt", //$NON-NLS-1$
            1));

    // Verify Changeset 2
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file1.txt"), //$NON-NLS-1$
            "$/project/folder/file1.txt", //$NON-NLS-1$
            2));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file1.txt"), //$NON-NLS-1$
            "$/project/folder2/file1.txt", //$NON-NLS-1$
            2));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file1.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file1.txt", //$NON-NLS-1$
            2));

    // Verify Changeset 3
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file2.txt"), //$NON-NLS-1$
            "$/project/folder/file2.txt", //$NON-NLS-1$
            3));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file2.txt"), //$NON-NLS-1$
            "$/project/folder2/file2.txt", //$NON-NLS-1$
            3));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file2.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file2.txt", //$NON-NLS-1$
            3));

    // Verify Git Repo configuration
    GitTFConfiguration gitRepoServerConfig = GitTFConfiguration.loadFrom(repository);

    assertEquals(gitRepoServerConfig.getServerURI(), projectCollectionURI);
    assertEquals(gitRepoServerConfig.getServerPath(), tfsPath);
    assertEquals(gitRepoServerConfig.getDeep(), defaultDeep);

    // Verify the number of commits
    Iterable<RevCommit> commits = git.log().call();

    assertNotNull(commits);

    int commitCounter = 0;
    for (RevCommit commit : commits) {
        assertEquals(commit.getFullMessage(), "comment"); //$NON-NLS-1$

        PersonIdent ownwer = commit.getAuthorIdent();
        assertEquals(ownwer.getEmailAddress(), "ownerName"); //$NON-NLS-1$
        assertEquals(ownwer.getName(), "ownerDisplayName"); //$NON-NLS-1$

        PersonIdent committer = commit.getCommitterIdent();
        assertEquals(committer.getEmailAddress(), "committerName"); //$NON-NLS-1$
        assertEquals(committer.getName(), "committerDisplayName"); //$NON-NLS-1$

        commitCounter++;
    }

    assertEquals(commitCounter, 1);

    // Verify the tags
    List<Ref> tags = git.tagList().call();
    assertEquals(1, tags.size());
}

From source file:com.microsoft.gittf.core.tasks.CloneTaskTest.java

License:Open Source License

@Test
public void testDeepCloneFilesAndFoldersSimple() throws Exception {
    URI projectCollectionURI = new URI("http://fakeCollection:8080/tfs/DefaultCollection"); //$NON-NLS-1$
    String tfsPath = "$/project"; //$NON-NLS-1$
    String gitRepositoryPath = Util.getRepositoryFile(getName()).getAbsolutePath();

    final MockVersionControlService mockVersionControlService = new MockVersionControlService();

    mockVersionControlService.AddFile("$/project/folder/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file0.txt", 1); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file0.txt", 1); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file1.txt", 2); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file1.txt", 2); //$NON-NLS-1$

    mockVersionControlService.AddFile("$/project/folder/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder2/file2.txt", 3); //$NON-NLS-1$
    mockVersionControlService.AddFile("$/project/folder/nestedFolder/file2.txt", 3); //$NON-NLS-1$

    Calendar date = Calendar.getInstance();
    date.set(2012, 11, 12, 18, 15);/*from w w  w . ja  v a 2  s. c o m*/

    MockChangesetProperties changesetProperties = new MockChangesetProperties("ownerDisplayName1", //$NON-NLS-1$
            "ownerName1", //$NON-NLS-1$
            "committerDisplayName1", //$NON-NLS-1$
            "committerName1", //$NON-NLS-1$
            "comment1", //$NON-NLS-1$
            date);

    mockVersionControlService.updateChangesetInformation(changesetProperties, 1);

    changesetProperties = new MockChangesetProperties("ownerDisplayName2", //$NON-NLS-1$
            "ownerName2", //$NON-NLS-1$
            "committerDisplayName2", //$NON-NLS-1$
            "committerName2", //$NON-NLS-1$
            "comment2", //$NON-NLS-1$
            date);

    mockVersionControlService.updateChangesetInformation(changesetProperties, 2);

    changesetProperties = new MockChangesetProperties("ownerDisplayName3", //$NON-NLS-1$
            "ownerName3", //$NON-NLS-1$
            "committerDisplayName3", //$NON-NLS-1$
            "committerName3", //$NON-NLS-1$
            "comment3", //$NON-NLS-1$
            date);

    mockVersionControlService.updateChangesetInformation(changesetProperties, 3);

    final Repository repository = RepositoryUtil.createNewRepository(gitRepositoryPath, false);
    final boolean defaultDeep = repository.getConfig().getInt(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.GENERAL_SUBSECTION, ConfigurationConstants.DEPTH,
            GitTFConstants.GIT_TF_SHALLOW_DEPTH) > 1;

    CloneTask cloneTask = new CloneTask(projectCollectionURI, mockVersionControlService, tfsPath, repository);
    cloneTask.setDepth(10);

    TaskStatus cloneTaskStatus = cloneTask.run(new NullTaskProgressMonitor());

    // Verify task completed without errors
    assertTrue(cloneTaskStatus.isOK());

    // Load Git Repo
    Git git = new Git(repository);
    git.checkout().setName("master").call(); //$NON-NLS-1$

    // Verify Changeset 1
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file0.txt"), //$NON-NLS-1$
            "$/project/folder/file0.txt", //$NON-NLS-1$
            1));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file0.txt"), //$NON-NLS-1$
            "$/project/folder2/file0.txt", //$NON-NLS-1$
            1));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file0.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file0.txt", //$NON-NLS-1$
            1));

    // Verify Changeset 2
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file1.txt"), //$NON-NLS-1$
            "$/project/folder/file1.txt", //$NON-NLS-1$
            2));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file1.txt"), //$NON-NLS-1$
            "$/project/folder2/file1.txt", //$NON-NLS-1$
            2));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file1.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file1.txt", //$NON-NLS-1$
            2));

    // Verify Changeset 3
    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder/file2.txt"), //$NON-NLS-1$
            "$/project/folder/file2.txt", //$NON-NLS-1$
            3));

    assertTrue(mockVersionControlService.verifyFileContent(new File(gitRepositoryPath, "folder2/file2.txt"), //$NON-NLS-1$
            "$/project/folder2/file2.txt", //$NON-NLS-1$
            3));

    assertTrue(mockVersionControlService.verifyFileContent(
            new File(gitRepositoryPath, "folder/nestedFolder/file2.txt"), //$NON-NLS-1$
            "$/project/folder/nestedFolder/file2.txt", //$NON-NLS-1$
            3));

    // Verify Git Repo configuration
    GitTFConfiguration gitRepoServerConfig = GitTFConfiguration.loadFrom(repository);

    assertEquals(gitRepoServerConfig.getServerURI(), projectCollectionURI);
    assertEquals(gitRepoServerConfig.getServerPath(), tfsPath);
    assertEquals(gitRepoServerConfig.getDeep(), defaultDeep);

    // Verify the number of commits
    Iterable<RevCommit> commits = git.log().call();

    assertNotNull(commits);

    int commitCounter = 3;
    for (RevCommit commit : commits) {
        assertEquals(commit.getFullMessage(), "comment" + Integer.toString(commitCounter)); //$NON-NLS-1$

        PersonIdent ownwer = commit.getAuthorIdent();
        assertEquals(ownwer.getEmailAddress(), "ownerName" + Integer.toString(commitCounter)); //$NON-NLS-1$
        assertEquals(ownwer.getName(), "ownerDisplayName" + Integer.toString(commitCounter)); //$NON-NLS-1$

        PersonIdent committer = commit.getCommitterIdent();
        assertEquals(committer.getEmailAddress(), "committerName" + Integer.toString(commitCounter)); //$NON-NLS-1$
        assertEquals(committer.getName(), "committerDisplayName" + Integer.toString(commitCounter)); //$NON-NLS-1$

        commitCounter--;
    }

    assertEquals(commitCounter, 0);

    // Verify the tags
    List<Ref> tags = git.tagList().call();
    assertEquals(3, tags.size());
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.egit.repositories.GitRepositoriesMap.java

License:Open Source License

private Map<String, String> getMappedBranches(final TfsGitRepositoryJson serverRepository,
        final Repository localRepository) {
    Map<String, String> mappedBranches = null;
    String upstreamURL = serverRepository.getRemoteUrl();
    try {/*from   www.j a  v a2 s .co  m*/
        upstreamURL = URIUtil.encodePath(serverRepository.getRemoteUrl());
    } catch (final URIException e) {
        log.error("Error encoding repository URL " + upstreamURL, e); //$NON-NLS-1$
    }

    final StoredConfig repositoryConfig = localRepository.getConfig();
    final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);

    for (final String remoteName : remotes) {
        final String remoteURL = repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName, URL_VALUE_NAME);

        if (remoteURL != null && remoteURL.equalsIgnoreCase(upstreamURL)) {
            if (mappedBranches == null) {
                mappedBranches = new HashMap<String, String>();
            }

            final Set<String> branches = repositoryConfig.getSubsections(BRANCHES_SECTION_NAME);

            for (final String branch : branches) {
                final String fullBranchName = Constants.R_HEADS + branch;

                final String[] remoteNames = repositoryConfig.getStringList(BRANCHES_SECTION_NAME, branch,
                        REMOTE_VALUE_NAME);
                final String[] mappedBrancheNames = repositoryConfig.getStringList(BRANCHES_SECTION_NAME,
                        branch, MERGE_VALUE_NAME);

                for (int k = 0; k < remoteNames.length; k++) {
                    if (remoteNames[k].equals(remoteName)) {
                        final String remoteBranchName = mappedBrancheNames[k];

                        if (!mappedBranches.containsKey(remoteBranchName)) {
                            mappedBranches.put(remoteBranchName, fullBranchName);
                        }

                        break;
                    }
                }
            }

            break;
        }
    }

    return mappedBranches;
}

From source file:com.microsoft.tfs.client.eclipse.ui.egit.teamexplorer.TeamExplorerGitRepositoriesSection.java

License:Open Source License

private void loadRegisteredRepositories() {
    repositoryMap = new TreeMap<String, Repository>();
    final List<String> repositoryFolders = Activator.getDefault().getRepositoryUtil()
            .getConfiguredRepositories();

    for (final String repositoryFolder : repositoryFolders) {
        final File folder = new File(repositoryFolder);
        if (!folder.exists() || !folder.isDirectory()) {
            continue;
        }//from w  w  w. j a  v  a2s.c  om

        if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
            continue;
        }

        final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);

        try {
            final Repository repo = rb.build();
            final StoredConfig repositoryConfig = repo.getConfig();
            final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);

            for (final String remoteName : remotes) {
                final String remoteURL = repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName,
                        URL_VALUE_NAME);
                repositoryMap.put(remoteURL, repo);
            }
        } catch (final Exception e) {
            log.error("Error loading local Git repository " + repositoryFolder, e); //$NON-NLS-1$
            continue;
        }
    }
}

From source file:com.miracle.apps.git.core.NetUtil.java

License:Open Source License

/**
 * Configures a {@link HttpURLConnection} according to the value of the
 * repositories configuration parameter "http.sslVerify". When this value is
 * false and when the URL is for the "https" protocol then all hostnames are
 * accepted and certificates are also accepted when they can't be validated
 *
 * @param repo/*from w w  w  .ja v  a  2s . com*/
 *            the repository to be asked for the configuration parameter
 *            http.sslVerify
 * @param conn
 *            the connection to be configured
 * @throws IOException
 */
public static void setSslVerification(Repository repo, HttpURLConnection conn) throws IOException {
    if ("https".equals(conn.getURL().getProtocol())) { //$NON-NLS-1$
        HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
        if (!repo.getConfig().getBoolean("http", "sslVerify", true)) { //$NON-NLS-1$ //$NON-NLS-2$
            try {
                SSLContext ctx = SSLContext.getInstance("TLS"); //$NON-NLS-1$
                ctx.init(null, trustAllCerts, null);
                httpsConn.setSSLSocketFactory(ctx.getSocketFactory());
                httpsConn.setHostnameVerifier(trustAllHostNames);
            } catch (KeyManagementException e) {
                throw new IOException(e.getMessage());
            } catch (NoSuchAlgorithmException e) {
                throw new IOException(e.getMessage());
            }
        }
    }
}

From source file:com.nlbhub.nlb.vcs.GitAdapter.java

License:Open Source License

private static void enableLongPaths(final Repository repository, final boolean save) throws IOException {
    StoredConfig config = repository.getConfig();
    config.setString("core", null, "longpaths", "true");
    if (save) {/*  w w w.ja va2s  . c o  m*/
        config.save();
    }
}