Search in sources :

Example 16 with RemoteConfig

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

the class SimpleFetchActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(true, event);
    if (repository == null)
        return null;
    RemoteConfig config = SimpleConfigureFetchDialog.getConfiguredRemote(repository);
    if (config == null) {
        MessageDialog.openInformation(getShell(event), UIText.SimpleFetchActionHandler_NothingToFetchDialogTitle, UIText.SimpleFetchActionHandler_NothingToFetchDialogMessage);
        return null;
    }
    new FetchOperationUI(repository, config, Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT), false).start();
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) FetchOperationUI(org.eclipse.egit.ui.internal.fetch.FetchOperationUI)

Example 17 with RemoteConfig

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

the class SimplePushActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(true, event);
    if (repository == null)
        return null;
    RemoteConfig config = SimpleConfigurePushDialog.getConfiguredRemote(repository);
    if (config == null) {
        MessageDialog.openInformation(getShell(event), UIText.SimplePushActionHandler_NothingToPushDialogTitle, UIText.SimplePushActionHandler_NothingToPushDialogMessage);
        return null;
    }
    PushOperationUI op = new PushOperationUI(repository, config.getName(), false);
    op.start();
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PushOperationUI(org.eclipse.egit.ui.internal.push.PushOperationUI) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 18 with RemoteConfig

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

the class RepositoriesViewContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    RepositoryTreeNode node = (RepositoryTreeNode) parentElement;
    Repository repo = node.getRepository();
    switch(node.getType()) {
        case BRANCHES:
            {
                List<RepositoryTreeNode> nodes = new ArrayList<>();
                nodes.add(new LocalNode(node, repo));
                nodes.add(new RemoteTrackingNode(node, repo));
                return nodes.toArray();
            }
        case LOCAL:
            {
                if (branchHierarchyMode) {
                    BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_HEADS));
                    List<RepositoryTreeNode> children = new ArrayList<>();
                    try {
                        for (IPath path : hierNode.getChildPaths()) {
                            children.add(new BranchHierarchyNode(node, node.getRepository(), path));
                        }
                        for (Ref ref : hierNode.getChildRefs()) {
                            children.add(new RefNode(node, node.getRepository(), ref));
                        }
                    } catch (Exception e) {
                        return handleException(e, node);
                    }
                    return children.toArray();
                } else {
                    List<RepositoryTreeNode<Ref>> refs = new ArrayList<>();
                    try {
                        for (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_HEADS).entrySet()) {
                            if (!refEntry.getValue().isSymbolic())
                                refs.add(new RefNode(node, repo, refEntry.getValue()));
                        }
                    } catch (Exception e) {
                        return handleException(e, node);
                    }
                    return refs.toArray();
                }
            }
        case REMOTETRACKING:
            {
                if (branchHierarchyMode) {
                    BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_REMOTES));
                    List<RepositoryTreeNode> children = new ArrayList<>();
                    try {
                        for (IPath path : hierNode.getChildPaths()) {
                            children.add(new BranchHierarchyNode(node, node.getRepository(), path));
                        }
                        for (Ref ref : hierNode.getChildRefs()) {
                            children.add(new RefNode(node, node.getRepository(), ref));
                        }
                    } catch (Exception e) {
                        return handleException(e, node);
                    }
                    return children.toArray();
                } else {
                    List<RepositoryTreeNode<Ref>> refs = new ArrayList<>();
                    try {
                        for (Entry<String, Ref> refEntry : getRefs(repo, Constants.R_REMOTES).entrySet()) {
                            if (!refEntry.getValue().isSymbolic())
                                refs.add(new RefNode(node, repo, refEntry.getValue()));
                        }
                    } catch (Exception e) {
                        return handleException(e, node);
                    }
                    return refs.toArray();
                }
            }
        case BRANCHHIERARCHY:
            {
                BranchHierarchyNode hierNode = (BranchHierarchyNode) node;
                List<RepositoryTreeNode> children = new ArrayList<>();
                try {
                    for (IPath path : hierNode.getChildPaths()) {
                        children.add(new BranchHierarchyNode(node, node.getRepository(), path));
                    }
                    for (Ref ref : hierNode.getChildRefs()) {
                        children.add(new RefNode(node, node.getRepository(), ref));
                    }
                } catch (IOException e) {
                    return handleException(e, node);
                }
                return children.toArray();
            }
        case TAGS:
            {
                return getTagsChildren(node, repo);
            }
        case ADDITIONALREFS:
            {
                List<RepositoryTreeNode<Ref>> refs = new ArrayList<>();
                try {
                    for (Entry<String, Ref> refEntry : getRefs(repo, RefDatabase.ALL).entrySet()) {
                        String name = refEntry.getKey();
                        if (!(name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_TAGS) || name.startsWith(Constants.R_REMOTES)))
                            refs.add(new AdditionalRefNode(node, repo, refEntry.getValue()));
                    }
                    for (Ref r : repo.getRefDatabase().getAdditionalRefs()) refs.add(new AdditionalRefNode(node, repo, r));
                } catch (Exception e) {
                    return handleException(e, node);
                }
                return refs.toArray();
            }
        case REMOTES:
            {
                List<RepositoryTreeNode<String>> remotes = new ArrayList<>();
                Repository rep = node.getRepository();
                Set<String> configNames = rep.getConfig().getSubsections(RepositoriesView.REMOTE);
                for (String configName : configNames) {
                    remotes.add(new RemoteNode(node, repo, configName));
                }
                return remotes.toArray();
            }
        case REPO:
            {
                List<RepositoryTreeNode<? extends Object>> nodeList = new ArrayList<>();
                nodeList.add(new BranchesNode(node, repo));
                nodeList.add(new TagsNode(node, repo));
                nodeList.add(new AdditionalRefsNode(node, repo));
                final boolean bare = repo.isBare();
                if (!bare)
                    nodeList.add(new WorkingDirNode(node, repo));
                nodeList.add(new RemotesNode(node, repo));
                if (!bare && hasStashedCommits(repo))
                    nodeList.add(new StashNode(node, repo));
                if (!bare && hasConfiguredSubmodules(repo))
                    nodeList.add(new SubmodulesNode(node, repo));
                return nodeList.toArray();
            }
        case WORKINGDIR:
            {
                List<RepositoryTreeNode<File>> children = new ArrayList<>();
                if (node.getRepository().isBare())
                    return children.toArray();
                File workingDir = repo.getWorkTree();
                if (!workingDir.exists())
                    return children.toArray();
                File[] childFiles = workingDir.listFiles();
                Arrays.sort(childFiles, new Comparator<File>() {

                    @Override
                    public int compare(File o1, File o2) {
                        if (o1.isDirectory()) {
                            if (o2.isDirectory()) {
                                return o1.compareTo(o2);
                            }
                            return -1;
                        } else if (o2.isDirectory()) {
                            return 1;
                        }
                        return o1.compareTo(o2);
                    }
                });
                for (File file : childFiles) {
                    if (file.isDirectory()) {
                        children.add(new FolderNode(node, repo, file));
                    } else {
                        children.add(new FileNode(node, repo, file));
                    }
                }
                return children.toArray();
            }
        case FOLDER:
            {
                List<RepositoryTreeNode<File>> children = new ArrayList<>();
                File parent = ((File) node.getObject());
                File[] childFiles = parent.listFiles();
                if (childFiles == null)
                    return children.toArray();
                Arrays.sort(childFiles, new Comparator<File>() {

                    @Override
                    public int compare(File o1, File o2) {
                        if (o1.isDirectory()) {
                            if (o2.isDirectory()) {
                                return o1.compareTo(o2);
                            }
                            return -1;
                        } else if (o2.isDirectory()) {
                            return 1;
                        }
                        return o1.compareTo(o2);
                    }
                });
                for (File file : childFiles) {
                    if (file.isDirectory()) {
                        children.add(new FolderNode(node, repo, file));
                    } else {
                        children.add(new FileNode(node, repo, file));
                    }
                }
                return children.toArray();
            }
        case REMOTE:
            {
                List<RepositoryTreeNode<String>> children = new ArrayList<>();
                String remoteName = (String) node.getObject();
                RemoteConfig rc;
                try {
                    rc = new RemoteConfig(node.getRepository().getConfig(), remoteName);
                } catch (URISyntaxException e) {
                    return handleException(e, node);
                }
                if (!rc.getURIs().isEmpty())
                    children.add(new FetchNode(node, node.getRepository(), rc.getURIs().get(0).toPrivateString()));
                int uriCount = rc.getPushURIs().size();
                if (uriCount == 0 && !rc.getURIs().isEmpty())
                    uriCount++;
                // at least one push specification
                if (uriCount > 0) {
                    URIish firstUri;
                    if (!rc.getPushURIs().isEmpty())
                        firstUri = rc.getPushURIs().get(0);
                    else
                        firstUri = rc.getURIs().get(0);
                    if (uriCount == 1)
                        children.add(new PushNode(node, node.getRepository(), firstUri.toPrivateString()));
                    else
                        children.add(new PushNode(node, node.getRepository(), // $NON-NLS-1$
                        firstUri.toPrivateString() + "..."));
                }
                return children.toArray();
            }
        case SUBMODULES:
            List<RepositoryNode> children = new ArrayList<>();
            try {
                SubmoduleWalk walk = SubmoduleWalk.forIndex(node.getRepository());
                while (walk.next()) {
                    Repository subRepo = walk.getRepository();
                    if (subRepo != null) {
                        Repository cachedRepo = null;
                        try {
                            cachedRepo = repositoryCache.lookupRepository(subRepo.getDirectory());
                        } finally {
                            subRepo.close();
                        }
                        if (cachedRepo != null)
                            children.add(new RepositoryNode(node, cachedRepo));
                    }
                }
            } catch (IOException e) {
                handleException(e, node);
            }
            return children.toArray();
        case STASH:
            List<StashedCommitNode> stashNodes = new ArrayList<>();
            int index = 0;
            try {
                for (RevCommit commit : Git.wrap(repo).stashList().call()) stashNodes.add(new StashedCommitNode(node, repo, index++, commit));
            } catch (Exception e) {
                handleException(e, node);
            }
            return stashNodes.toArray();
        case FILE:
        // fall through
        case REF:
        // fall through
        case PUSH:
        // fall through
        case TAG:
        // fall through
        case FETCH:
        // fall through
        case ERROR:
        // fall through
        case STASHED_COMMIT:
        // fall through
        case ADDITIONALREF:
            return null;
    }
    return null;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Set(java.util.Set) FolderNode(org.eclipse.egit.ui.internal.repository.tree.FolderNode) TagsNode(org.eclipse.egit.ui.internal.repository.tree.TagsNode) ArrayList(java.util.ArrayList) RemotesNode(org.eclipse.egit.ui.internal.repository.tree.RemotesNode) URISyntaxException(java.net.URISyntaxException) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) Comparator(java.util.Comparator) Entry(java.util.Map.Entry) FetchNode(org.eclipse.egit.ui.internal.repository.tree.FetchNode) SubmodulesNode(org.eclipse.egit.ui.internal.repository.tree.SubmodulesNode) List(java.util.List) ArrayList(java.util.ArrayList) WorkingDirNode(org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) BranchesNode(org.eclipse.egit.ui.internal.repository.tree.BranchesNode) AdditionalRefsNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefsNode) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) StashNode(org.eclipse.egit.ui.internal.repository.tree.StashNode) RemoteNode(org.eclipse.egit.ui.internal.repository.tree.RemoteNode) IOException(java.io.IOException) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) SubmoduleWalk(org.eclipse.jgit.submodule.SubmoduleWalk) PushNode(org.eclipse.egit.ui.internal.repository.tree.PushNode) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RemoteTrackingNode(org.eclipse.egit.ui.internal.repository.tree.RemoteTrackingNode) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) LocalNode(org.eclipse.egit.ui.internal.repository.tree.LocalNode) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) File(java.io.File) BranchHierarchyNode(org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode) FileNode(org.eclipse.egit.ui.internal.repository.tree.FileNode)

Example 19 with RemoteConfig

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

the class PullWizardPage method showNewRemoteDialog.

private void showNewRemoteDialog() {
    AddRemoteWizard wizard = new AddRemoteWizard(repository);
    WizardDialog dialog = new WizardDialog(getShell(), wizard);
    int result = dialog.open();
    if (result == Window.OK) {
        URIish uri = wizard.getUri();
        String remoteName = wizard.getRemoteName();
        try {
            StoredConfig repoConfig = repository.getConfig();
            RemoteConfig newRemoteConfig = new RemoteConfig(repoConfig, remoteName);
            newRemoteConfig.addURI(uri);
            RefSpec defaultFetchSpec = new RefSpec().setForceUpdate(true).setSourceDestination(// $NON-NLS-1$
            Constants.R_HEADS + "*", // $NON-NLS-1$
            Constants.R_REMOTES + remoteName + "/*");
            newRemoteConfig.addFetchRefSpec(defaultFetchSpec);
            newRemoteConfig.update(repoConfig);
            repoConfig.save();
            List<RemoteConfig> allRemoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
            remoteSelectionCombo.setItems(allRemoteConfigs);
            // isn't what's stored and returned by getAllRemoteConfigs
            for (RemoteConfig current : allRemoteConfigs) {
                if (newRemoteConfig.getName().equals(current.getName())) {
                    setSelectedRemote(current);
                }
            }
        } catch (URISyntaxException ex) {
            Activator.logError(ex.getMessage(), ex);
        } catch (IOException ex) {
            Activator.logError(ex.getMessage(), ex);
        }
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) StoredConfig(org.eclipse.jgit.lib.StoredConfig) RefSpec(org.eclipse.jgit.transport.RefSpec) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AddRemoteWizard(org.eclipse.egit.ui.internal.push.AddRemoteWizard)

Example 20 with RemoteConfig

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

the class PullWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    try {
        this.remoteConfigs = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
        Collections.sort(remoteConfigs, new Comparator<RemoteConfig>() {

            @Override
            public int compare(RemoteConfig first, RemoteConfig second) {
                return String.CASE_INSENSITIVE_ORDER.compare(first.getName(), second.getName());
            }
        });
        setDefaultUpstreamConfig();
    } catch (URISyntaxException e) {
        this.remoteConfigs = new ArrayList<>();
        handleError(e);
    }
    Composite res = new Composite(parent, SWT.NONE);
    res.setLayout(new GridLayout(3, false));
    Label remoteLabel = new Label(res, SWT.NONE);
    remoteLabel.setText(UIText.PushBranchPage_RemoteLabel);
    this.remoteSelectionCombo = new RemoteSelectionCombo(res, SWT.NONE, SelectionType.PUSH);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(remoteSelectionCombo);
    setRemoteConfigs();
    remoteSelectionCombo.addRemoteSelectionListener(new IRemoteSelectionListener() {

        @Override
        public void remoteSelected(RemoteConfig rc) {
            remoteConfig = rc;
            setRefAssist(rc);
            checkPage();
        }
    });
    Button newRemoteButton = new Button(res, SWT.PUSH);
    newRemoteButton.setText(UIText.PushBranchPage_NewRemoteButton);
    GridDataFactory.fillDefaults().applyTo(newRemoteButton);
    newRemoteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showNewRemoteDialog();
        }
    });
    Label branchNameLabel = new Label(res, SWT.NONE);
    branchNameLabel.setText(UIText.PullWizardPage_referenceLabel);
    branchNameLabel.setToolTipText(UIText.PullWizardPage_referenceTooltip);
    remoteBranchNameText = new Text(res, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(remoteBranchNameText);
    UIUtils.addRefContentProposalToText(remoteBranchNameText, this.repository, () -> {
        if (PullWizardPage.this.assist != null) {
            return PullWizardPage.this.assist.getRefsForContentAssist(false, true);
        }
        return Collections.emptyList();
    }, true);
    remoteBranchNameText.setText(getSuggestedBranchName());
    remoteBranchNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            checkPage();
        }
    });
    this.upstreamConfigComponent = new BranchRebaseModeCombo(res);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).align(SWT.BEGINNING, SWT.CENTER).applyTo(upstreamConfigComponent.getViewer().getCombo());
    this.upstreamConfigComponent.getViewer().addSelectionChangedListener((event) -> upstreamConfig = upstreamConfigComponent.getRebaseMode());
    if (upstreamConfig != null) {
        upstreamConfigComponent.setRebaseMode(upstreamConfig);
    }
    if (this.fullBranch != null && this.fullBranch.startsWith(Constants.R_HEADS)) {
        this.rememberConfigForBranch = new Button(res, SWT.CHECK);
        GridData checkboxLayoutData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1);
        checkboxLayoutData.verticalIndent = 20;
        this.rememberConfigForBranch.setText(UIText.UpstreamConfigComponent_ConfigureUpstreamCheck);
        this.rememberConfigForBranch.setToolTipText(UIText.UpstreamConfigComponent_ConfigureUpstreamToolTip);
        this.rememberConfigForBranch.setLayoutData(checkboxLayoutData);
        this.rememberConfigForBranch.setSelection(this.configureUpstream);
        this.rememberConfigForBranch.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                configureUpstream = rememberConfigForBranch.getSelection();
                checkPage();
            }
        });
    }
    setPageComplete(isPageComplete());
    setControl(res);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) BranchRebaseModeCombo(org.eclipse.egit.ui.internal.components.BranchRebaseModeCombo) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) URISyntaxException(java.net.URISyntaxException) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) IRemoteSelectionListener(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo.IRemoteSelectionListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) RemoteSelectionCombo(org.eclipse.egit.ui.internal.components.RemoteSelectionCombo)

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