Search in sources :

Example 21 with RemoteConfig

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

the class PushWizard method createPushOperation.

private PushOperation createPushOperation(boolean calledFromRepoPage) {
    try {
        final PushOperationSpecification spec;
        final RemoteConfig config = repoPage.getSelection().getConfig();
        if (calledFromRepoPage) {
            // obtain the push ref specs from the configuration
            // use our own list here, as the config returns a non-modifiable
            // list
            final Collection<RefSpec> pushSpecs = new ArrayList<>();
            pushSpecs.addAll(config.getPushRefSpecs());
            final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, pushSpecs, config.getFetchRefSpecs());
            spec = new PushOperationSpecification();
            for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
        } else if (confirmPage.isConfirmed()) {
            final PushOperationResult confirmedResult = confirmPage.getConfirmedResult();
            spec = confirmedResult.deriveSpecification(confirmPage.isRequireUnchangedSelected());
        } else {
            final Collection<RefSpec> fetchSpecs;
            if (config != null)
                fetchSpecs = config.getFetchRefSpecs();
            else
                fetchSpecs = null;
            final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, refSpecPage.getRefSpecs(), fetchSpecs);
            if (updates.isEmpty()) {
                ErrorDialog.openError(getShell(), UIText.PushWizard_missingRefsTitle, null, new Status(IStatus.ERROR, Activator.getPluginId(), UIText.PushWizard_missingRefsMessage));
                return null;
            }
            spec = new PushOperationSpecification();
            for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
        }
        int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
        return new PushOperation(localDb, spec, false, timeout);
    } catch (final IOException e) {
        ErrorDialog.openError(getShell(), UIText.PushWizard_cantPrepareUpdatesTitle, UIText.PushWizard_cantPrepareUpdatesMessage, new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage(), e));
        return null;
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) URIish(org.eclipse.jgit.transport.URIish) PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PushOperation(org.eclipse.egit.core.op.PushOperation) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 22 with RemoteConfig

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

the class SimpleConfigurePushDialog method getConfiguredRemote.

/**
 * @param repository
 * @return the configured remote for the current branch if any, or null
 */
public static RemoteConfig getConfiguredRemote(Repository repository) {
    String branch;
    try {
        branch = repository.getBranch();
    } catch (IOException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    if (branch == null)
        return null;
    String remoteName = null;
    if (!ObjectId.isId(branch))
        remoteName = repository.getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_REMOTE_SECTION);
    // check if we find the configured and default Remotes
    List<RemoteConfig> allRemotes;
    try {
        allRemotes = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
    } catch (URISyntaxException e) {
        allRemotes = new ArrayList<>();
    }
    RemoteConfig configuredConfig = null;
    RemoteConfig defaultConfig = null;
    for (RemoteConfig config : allRemotes) {
        if (remoteName != null && config.getName().equals(remoteName))
            configuredConfig = config;
        if (config.getName().equals(Constants.DEFAULT_REMOTE_NAME))
            defaultConfig = config;
    }
    if (configuredConfig != null)
        return configuredConfig;
    if (defaultConfig != null)
        if (!defaultConfig.getPushRefSpecs().isEmpty())
            return defaultConfig;
    return null;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 23 with RemoteConfig

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

the class PushBranchWizard method configureNewRemote.

private void configureNewRemote(URIish uri) throws URISyntaxException, IOException {
    StoredConfig config = repository.getConfig();
    String remoteName = getRemoteName();
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    remoteConfig.addURI(uri);
    RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(// $NON-NLS-1$
    Constants.R_HEADS + "*", // $NON-NLS-1$
    Constants.R_REMOTES + remoteName + "/*");
    remoteConfig.addFetchRefSpec(defaultFetchSpec);
    remoteConfig.update(config);
    config.save();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) RefSpec(org.eclipse.jgit.transport.RefSpec) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 24 with RemoteConfig

use of org.eclipse.jgit.transport.RemoteConfig in project Android-Password-Store by zeapo.

the class PasswordRepository method addRemote.

// TODO add multiple remotes support for pull/push
public static void addRemote(String name, String url, Boolean replace) {
    StoredConfig storedConfig = repository.getConfig();
    Set<String> remotes = storedConfig.getSubsections("remote");
    if (!remotes.contains(name)) {
        try {
            URIish uri = new URIish(url);
            RefSpec refSpec = new RefSpec("+refs/head/*:refs/remotes/" + name + "/*");
            RemoteConfig remoteConfig = new RemoteConfig(storedConfig, name);
            remoteConfig.addFetchRefSpec(refSpec);
            remoteConfig.addPushRefSpec(refSpec);
            remoteConfig.addURI(uri);
            remoteConfig.addPushURI(uri);
            remoteConfig.update(storedConfig);
            storedConfig.save();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (replace) {
        try {
            URIish uri = new URIish(url);
            RemoteConfig remoteConfig = new RemoteConfig(storedConfig, name);
            // remove the first and eventually the only uri
            if (remoteConfig.getURIs().size() > 0) {
                remoteConfig.removeURI(remoteConfig.getURIs().get(0));
            }
            if (remoteConfig.getPushURIs().size() > 0) {
                remoteConfig.removePushURI(remoteConfig.getPushURIs().get(0));
            }
            remoteConfig.addURI(uri);
            remoteConfig.addPushURI(uri);
            remoteConfig.update(storedConfig);
            storedConfig.save();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URIish(org.eclipse.jgit.transport.URIish) RefSpec(org.eclipse.jgit.transport.RefSpec) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 25 with RemoteConfig

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

the class EGitUtils method getRemoteURIs.

/**
 * Returns the URIish's for the remote on the given project.
 *
 * @param remoteName
 * @param project
 * @return
 * @throws CoreException
 */
public static List<URIish> getRemoteURIs(String remoteName, IProject project) throws CoreException {
    List<URIish> uris = Collections.emptyList();
    RemoteConfig remoteConfig = getRemoteByName(remoteName, getRepository(project));
    if (remoteConfig != null) {
        uris = remoteConfig.getURIs();
    }
    return uris;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) 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