Search in sources :

Example 41 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project jbosstools-openshift by jbosstools.

the class EGitUtilsTest method shouldFetchAndHaveRemoteRef.

@Test
public void shouldFetchAndHaveRemoteRef() throws Exception {
    // given
    testRepository.createAndCheckoutBranch(Constants.HEAD, REPO_BRANCH);
    RemoteConfig remoteConfig = EGitUtils.getRemoteByName("origin", testRepositoryClone.getRepository());
    String fullRef = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + REPO_BRANCH;
    assertThat(testRepositoryClone.getRepository().findRef(fullRef), is(nullValue()));
    // when
    EGitUtils.fetch(remoteConfig, testRepositoryClone.getRepository(), new NullProgressMonitor());
    // then
    assertThat(testRepositoryClone.getRepository().findRef(fullRef), is(not(nullValue())));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) Test(org.junit.Test)

Example 42 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class BranchConfigurationDialog method addBranchItemsForRemote.

private void addBranchItemsForRemote(String remote) throws IOException, URISyntaxException {
    RemoteConfig remoteConfig = new RemoteConfig(myConfig, remote);
    List<RefSpec> fetchSpecs = remoteConfig.getFetchRefSpecs();
    if (fetchSpecs.isEmpty()) {
        return;
    }
    Collection<Ref> allRefs = myRepository.getRefDatabase().getRefs(Constants.R_REFS).values();
    for (Ref ref : allRefs) {
        for (RefSpec fetchSpec : fetchSpecs) {
            // destination to source.
            if (fetchSpec.matchDestination(ref)) {
                RefSpec source = fetchSpec.expandFromDestination(ref);
                String refNameOnRemote = source.getSource();
                branchText.add(refNameOnRemote);
            }
        }
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefSpec(org.eclipse.jgit.transport.RefSpec) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 43 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class FetchWizard method saveConfig.

private void saveConfig() {
    final RemoteConfig rc = repoPage.getSelection().getConfig();
    rc.setFetchRefSpecs(refSpecPage.getRefSpecs());
    rc.setTagOpt(refSpecPage.getTagOpt());
    final StoredConfig config = localDb.getConfig();
    rc.update(config);
    try {
        config.save();
    } catch (final IOException e) {
        ErrorDialog.openError(getShell(), UIText.FetchWizard_cantSaveTitle, UIText.FetchWizard_cantSaveMessage, new Status(IStatus.WARNING, Activator.getPluginId(), e.getMessage(), e));
    // Continue, it's not critical.
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 44 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class SynchronizeViewPushTest method prepare.

@Before
public void prepare() throws Exception {
    Repository childRepository = lookupRepository(childRepositoryFile);
    Repository repository = lookupRepository(repositoryFile);
    StoredConfig config = repository.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
    remoteConfig.addURI(new URIish(childRepository.getDirectory().getParentFile().toURI().toURL()));
    remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
    remoteConfig.update(config);
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin");
    config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master");
    config.save();
    FetchOperation fetchOperation = new FetchOperation(repository, remoteConfig, 60, false);
    fetchOperation.run(null);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) RefSpec(org.eclipse.jgit.transport.RefSpec) FetchOperation(org.eclipse.egit.core.op.FetchOperation) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) Before(org.junit.Before)

Example 45 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project egit by eclipse.

the class GerritUtil method findRemoteConfig.

/**
 * Find the remote config for the given remote name
 *
 * @param config
 *            the configuration containing the remote config
 * @param remoteName
 *            the name of the remote to find
 * @return the found remoteConfig or {@code null}
 * @throws URISyntaxException
 *             if the configuration contains an illegal URI
 */
public static RemoteConfig findRemoteConfig(Config config, String remoteName) throws URISyntaxException {
    RemoteConfig remoteConfig = null;
    List<RemoteConfig> allRemoteConfigs = RemoteConfig.getAllRemoteConfigs(config);
    for (RemoteConfig rc : allRemoteConfigs) {
        if (rc.getName().equals(remoteName)) {
            remoteConfig = rc;
            break;
        }
    }
    return remoteConfig;
}
Also used : RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Aggregations

RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)63 URISyntaxException (java.net.URISyntaxException)23 StoredConfig (org.eclipse.jgit.lib.StoredConfig)21 URIish (org.eclipse.jgit.transport.URIish)21 IOException (java.io.IOException)16 RefSpec (org.eclipse.jgit.transport.RefSpec)14 Repository (org.eclipse.jgit.lib.Repository)13 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 Button (org.eclipse.swt.widgets.Button)6 Composite (org.eclipse.swt.widgets.Composite)6 File (java.io.File)5 Git (org.eclipse.jgit.api.Git)5 Ref (org.eclipse.jgit.lib.Ref)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Label (org.eclipse.swt.widgets.Label)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 UIText (org.eclipse.egit.ui.internal.UIText)4