Search in sources :

Example 11 with RemoteConfig

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

the class RemoteSelectionCombo method setItems.

/**
 * Set the available items.
 *
 * @param remoteConfigs
 * @return the initially selected remote config, defaults to the origin
 *         remote if there is one
 */
public RemoteConfig setItems(List<RemoteConfig> remoteConfigs) {
    this.remoteConfigs = remoteConfigs;
    final String[] items = new String[remoteConfigs.size()];
    int i = 0;
    for (final RemoteConfig rc : remoteConfigs) items[i++] = getTextForRemoteConfig(rc);
    remoteCombo.setItems(items);
    RemoteConfig defaultRemoteConfig = getDefaultRemoteConfig();
    setSelectedRemote(defaultRemoteConfig);
    return defaultRemoteConfig;
}
Also used : RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 12 with RemoteConfig

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

the class AbstractConfigureRemoteDialog method buttonPressed.

@Override
protected final void buttonPressed(int buttonId) {
    switch(buttonId) {
        case DRY_RUN:
            try {
                new ProgressMonitorDialog(getShell()).run(true, true, (monitor) -> dryRun(monitor));
            } catch (InvocationTargetException e) {
                Activator.showError(e.getMessage(), e);
            } catch (InterruptedException e1) {
            // Ignore cancellation here
            }
            return;
        case REVERT:
            try {
                config = new RemoteConfig(repository.getConfig(), config.getName());
                updateControls();
            } catch (URISyntaxException e) {
                Activator.handleError(e.getMessage(), e, true);
            }
            return;
        case OK:
        case SAVE_ONLY:
            StoredConfig repoConfig = getRepository().getConfig();
            boolean saved = false;
            try {
                config.update(repoConfig);
                repoConfig.save();
                saved = true;
            } catch (IOException e) {
                Activator.handleError(e.getMessage(), e, true);
            }
            if (saved) {
                GerritDialogSettings.updateRemoteConfig(repository, config);
            }
            if (buttonId == OK) {
                performOperation();
            }
            okPressed();
            return;
        default:
            break;
    }
    super.buttonPressed(buttonId);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with RemoteConfig

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

the class PushConfiguredRemoteCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    RepositoryTreeNode node = getSelectedNodes(event).get(0);
    RemoteConfig config = getRemoteConfig(node);
    if (config == null) {
        MessageDialog.openInformation(getShell(event), UIText.SimplePushActionHandler_NothingToPushDialogTitle, UIText.SimplePushActionHandler_NothingToPushDialogMessage);
        return null;
    }
    new PushOperationUI(node.getRepository(), config.getName(), false).start();
    return null;
}
Also used : RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) PushOperationUI(org.eclipse.egit.ui.internal.push.PushOperationUI) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 14 with RemoteConfig

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

the class RepositoriesViewPropertyTester method internalTest.

private boolean internalTest(Object receiver, String property) {
    if (!(receiver instanceof RepositoryTreeNode))
        return false;
    RepositoryTreeNode node = (RepositoryTreeNode) receiver;
    Repository repository = node.getRepository();
    if (repository == null) {
        return false;
    }
    if (property.equals("isBare")) {
        // $NON-NLS-1$
        return repository.isBare();
    }
    if (property.equals("containsHead")) {
        // $NON-NLS-1$
        return containsHead(repository);
    }
    if (ResourcePropertyTester.testRepositoryState(repository, property)) {
        return true;
    }
    if (property.equals("isRefCheckedOut")) {
        // $NON-NLS-1$
        if (node instanceof BranchHierarchyNode) {
            try {
                for (Ref ref : ((BranchHierarchyNode) node).getChildRefsRecursive()) {
                    if (isRefCheckedOut(repository, ref)) {
                        return true;
                    }
                }
            } catch (IOException e) {
                return false;
            }
        }
        if (!(node.getObject() instanceof Ref))
            return false;
        Ref ref = (Ref) node.getObject();
        return isRefCheckedOut(repository, ref);
    }
    if (property.equals("isLocalBranch")) {
        // $NON-NLS-1$
        if (!(node.getObject() instanceof Ref))
            return false;
        Ref ref = (Ref) node.getObject();
        return ref.getName().startsWith(Constants.R_HEADS);
    }
    if (property.equals("fetchExists")) {
        // $NON-NLS-1$
        if (node instanceof RemoteNode) {
            String configName = ((RemoteNode) node).getObject();
            RemoteConfig rconfig;
            try {
                rconfig = new RemoteConfig(repository.getConfig(), configName);
            } catch (URISyntaxException e2) {
                return false;
            }
            // we need to have a fetch ref spec and a fetch URI
            return !rconfig.getFetchRefSpecs().isEmpty() && !rconfig.getURIs().isEmpty();
        }
    }
    if (property.equals("pushExists")) {
        // $NON-NLS-1$
        if (node instanceof RemoteNode) {
            String configName = ((RemoteNode) node).getObject();
            RemoteConfig rconfig;
            try {
                rconfig = new RemoteConfig(repository.getConfig(), configName);
            } catch (URISyntaxException e2) {
                return false;
            }
            // we need to have at least a push ref spec and any URI
            return !rconfig.getPushRefSpecs().isEmpty() && (!rconfig.getPushURIs().isEmpty() || !rconfig.getURIs().isEmpty());
        }
    }
    if (property.equals("canStash")) {
        // $NON-NLS-1$
        return repository.getRepositoryState().canCommit();
    }
    if (property.equals("canMerge")) {
        // $NON-NLS-1$
        if (repository.getRepositoryState() != RepositoryState.SAFE)
            return false;
        try {
            String branch = repository.getFullBranch();
            if (branch == null)
                // fail gracefully...
                return false;
            return branch.startsWith(Constants.R_HEADS);
        } catch (IOException e) {
            return false;
        }
    }
    if ("isSubmodule".equals(property)) {
        // $NON-NLS-1$
        RepositoryTreeNode<?> parent = node.getParent();
        return parent != null && parent.getType() == RepositoryTreeNodeType.SUBMODULES;
    }
    return false;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 15 with RemoteConfig

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

the class GitFlowConfig method getDefaultRemoteConfig.

/**
 * @return Configured origin.
 */
public RemoteConfig getDefaultRemoteConfig() {
    StoredConfig rc = repository.getConfig();
    RemoteConfig result;
    try {
        result = new RemoteConfig(rc, DEFAULT_REMOTE_NAME);
    } catch (URISyntaxException e) {
        throw new IllegalStateException(e);
    }
    return result;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URISyntaxException(java.net.URISyntaxException) 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