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:org.eclipse.egit.ui.internal.gerrit.ConfigureGerritWizard.java

License:Open Source License

/**
 * @param repository the repository//from ww w . j  a va  2 s.  c o m
 * @param remoteName the name of the remote in the configuration
 *
 */
public ConfigureGerritWizard(Repository repository, String remoteName) {
    super();
    setWindowTitle(UIText.ConfigureGerritWizard_title);
    setDefaultPageImageDescriptor(UIIcons.WIZBAN_IMPORT_REPO);
    setNeedsProgressMonitor(true);
    gerritConfiguration = new GerritConfigurationPage(repository, remoteName) {
        @Override
        public void setVisible(boolean visible) {
            if (visible)
                configurePage();
            super.setVisible(visible);
        }

    };
    this.config = repository.getConfig();
    this.remoteName = remoteName;

}

From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java

License:Open Source License

/**
 * @param commit//from  w  ww.j  av  a 2  s.  c  om
 * @param repository
 * @param currentBranch
 * @return ref pointing to the given commit, prefers tracking branch if
 *         multiple refs are available
 */
protected Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java

License:Open Source License

private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {//from  w ww.  j  ava2 s  .  com
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizard.java

License:Open Source License

private PushBranchWizard(final Repository repository, ObjectId commitToPush, Ref ref) {
    this.repository = repository;
    this.commitToPush = commitToPush;
    this.ref = ref;
    assert (this.repository != null);
    assert (this.commitToPush != null);

    Set<String> remoteNames = repository.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
    if (remoteNames.isEmpty())
        addRemotePage = new AddRemotePage(repository);

    pushBranchPage = new PushBranchPage(repository, commitToPush, ref) {
        @Override/*from w ww.  j av  a 2  s  . c  om*/
        public void setVisible(boolean visible) {
            if (visible && addRemotePage != null) {
                setSelectedRemote(addRemotePage.getRemoteName(), addRemotePage.getSelection().getURI());
            }
            super.setVisible(visible);
        }
    };
    // Don't show button if we're configuring a remote in the first step
    pushBranchPage.setShowNewRemoteButton(addRemotePage == null);

    confirmationPage = new ConfirmationPage(repository) {
        @Override
        public void setVisible(boolean visible) {
            setSelection(getRepositorySelection(), getRefSpecs());
            AddRemotePage remotePage = getAddRemotePage();
            if (remotePage != null)
                setCredentials(remotePage.getCredentials());
            super.setVisible(visible);
        }
    };

    setDefaultPageImageDescriptor(UIIcons.WIZBAN_PUSH);
}

From source file:org.eclipse.egit.ui.internal.push.PushWizard.java

License:Open Source License

/**
 * Create push wizard for specified local repository.
 *
 * @param localDb/*from ww w.  j  a  v a 2 s  . c  o m*/
 *            repository to push from.
 * @throws URISyntaxException
 *             when configuration of this repository contains illegal URIs.
 */
public PushWizard(final Repository localDb) throws URISyntaxException {
    this.localDb = localDb;
    final List<RemoteConfig> remotes = RemoteConfig.getAllRemoteConfigs(localDb.getConfig());
    repoPage = new RepositorySelectionPage(false, remotes, null);
    refSpecPage = new RefSpecPage(localDb, true) {
        @Override
        public void setVisible(boolean visible) {
            if (visible) {
                setSelection(repoPage.getSelection());
                setCredentials(repoPage.getCredentials());
            }
            super.setVisible(visible);
        }
    };
    confirmPage = new ConfirmationPage(localDb) {
        @Override
        public void setVisible(boolean visible) {
            if (visible) {
                setSelection(repoPage.getSelection(), refSpecPage.getRefSpecs());
                setCredentials(repoPage.getCredentials());
            }
            super.setVisible(visible);
        }
    };
    // TODO use/create another cool icon
    setDefaultPageImageDescriptor(UIIcons.WIZBAN_IMPORT_REPO);
    setNeedsProgressMonitor(true);
}

From source file:org.eclipse.egit.ui.internal.push.SimpleConfigurePushDialog.java

License:Open Source License

/**
 * @param shell// w  w w  .  j  a  v  a2s. com
 * @param repository
 * @param remoteName
 *            the remote to use
 * @return the dialog to open, or null
 */
public static Dialog getDialog(Shell shell, Repository repository, String remoteName) {
    RemoteConfig configToUse;
    try {
        configToUse = new RemoteConfig(repository.getConfig(), remoteName);
    } catch (URISyntaxException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    return new SimpleConfigurePushDialog(shell, repository, configToUse, false);
}

From source file:org.eclipse.egit.ui.internal.push.SimplePushRefWizard.java

License:Open Source License

private SimplePushRefWizard(Repository repo, ObjectId objectId, String name, String title)
        throws URISyntaxException {
    final List<RemoteConfig> remotes = RemoteConfig.getAllRemoteConfigs(repo.getConfig());

    this.nicePushName = name;
    this.pushObj = objectId;
    this.repo = repo;

    repoPage = new RepositorySelectionPage(false, remotes, null);
    targetPage = new SimplePushSpecPage(nicePushName, repo) {
        @Override/*from w  w  w . j  ava  2  s .  c o m*/
        public void setVisible(boolean visible) {
            super.setVisible(visible);

            if (visible)
                try {
                    if (assist != null && assist.getRepository().equals(SimplePushRefWizard.this.repo)
                            && assist.getRemoteURI().equals(repoPage.getSelection().getURI(true)))
                        return;

                    assist = new RefContentAssistProvider(SimplePushRefWizard.this.repo,
                            repoPage.getSelection().getURI(true), getShell());

                } finally {
                    updateDestinationField();
                }
        }
    };
    setWindowTitle(title);
}

From source file:org.eclipse.egit.ui.internal.repository.ConfigureRemoteWizard.java

License:Open Source License

/**
 *
 * @param repository//from  w  ww.  j  ava2  s. c om
 * @param remoteName
 * @param push
 */
public ConfigureRemoteWizard(Repository repository, String remoteName, boolean push) {
    super.setNeedsProgressMonitor(true);
    myConfiguration = repository.getConfig();
    myRemoteName = remoteName;
    pushMode = push;

    try {
        myRemoteConfiguration = new RemoteConfig(myConfiguration, remoteName);
    } catch (URISyntaxException e) {
        // handle this by trying to cleanup the configuration entries
        myConfiguration.unsetSection("remote", remoteName); //$NON-NLS-1$
        // TODO Exception handling
        try {
            myRemoteConfiguration = new RemoteConfig(myConfiguration, remoteName);
        } catch (URISyntaxException e1) {
            // panic
            throw new IllegalStateException(e1.getMessage());
        }
    }

    configureFetchUriPage = new ConfigureUriPage(true, myRemoteConfiguration);
    if (!pushMode)
        addPage(configureFetchUriPage);

    configureFetchSpecPage = new RefSpecPage(repository, false);
    if (!pushMode)
        addPage(configureFetchSpecPage);

    configurePushUriPage = new ConfigureUriPage(false, myRemoteConfiguration);
    if (pushMode)
        addPage(configurePushUriPage);

    configurePushSpecPage = new RefSpecPage(repository, true);
    if (pushMode)
        addPage(configurePushSpecPage);

    setWindowTitle(NLS.bind(UIText.ConfigureRemoteWizard_WizardTitle_Change, myRemoteName));
}

From source file:org.eclipse.egit.ui.internal.repository.NewRemoteWizard.java

License:Open Source License

/**
 *
 * @param repository/*from ww w .  j a v  a  2  s  .co m*/
 */
public NewRemoteWizard(Repository repository) {
    super.setNeedsProgressMonitor(true);
    myConfiguration = repository.getConfig();

    selNamePage = new SelectRemoteNamePage();
    addPage(selNamePage);

    configureFetchUriPage = new ConfigureUriPage(true, null);
    addPage(configureFetchUriPage);

    configureFetchSpecPage = new RefSpecPage(repository, false);
    addPage(configureFetchSpecPage);

    configurePushUriPage = new ConfigureUriPage(false, null);
    addPage(configurePushUriPage);

    configurePushSpecPage = new RefSpecPage(repository, true);
    addPage(configurePushSpecPage);

    setWindowTitle(UIText.ConfigureRemoteWizard_WizardTitle_New);
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider.java

License:Open Source License

public Object[] getChildren(Object parentElement) {

    RepositoryTreeNode node = (RepositoryTreeNode) parentElement;
    Repository repo = node.getRepository();

    switch (node.getType()) {

    case BRANCHES: {
        List<RepositoryTreeNode> nodes = new ArrayList<RepositoryTreeNode>();
        nodes.add(new LocalNode(node, repo));
        nodes.add(new RemoteTrackingNode(node, repo));
        return nodes.toArray();
    }/*  www  .  j  av  a 2 s .  c  o m*/

    case LOCAL: {
        if (branchHierarchyMode) {
            BranchHierarchyNode hierNode = new BranchHierarchyNode(node, repo, new Path(Constants.R_HEADS));
            List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
            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();
        } else {
            List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
            try {
                for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_HEADS)
                        .entrySet()) {
                    if (!refEntry.getValue().isSymbolic())
                        refs.add(new RefNode(node, repo, refEntry.getValue()));
                }
            } catch (IOException 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<RepositoryTreeNode>();
            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();
        } else {
            List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
            try {
                for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_REMOTES)
                        .entrySet()) {
                    if (!refEntry.getValue().isSymbolic())
                        refs.add(new RefNode(node, repo, refEntry.getValue()));
                }
            } catch (IOException e) {
                return handleException(e, node);
            }

            return refs.toArray();
        }
    }

    case BRANCHHIERARCHY: {
        BranchHierarchyNode hierNode = (BranchHierarchyNode) node;
        List<RepositoryTreeNode> children = new ArrayList<RepositoryTreeNode>();
        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: {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();

        try {
            for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(Constants.R_TAGS).entrySet()) {
                refs.add(new TagNode(node, repo, refEntry.getValue()));
            }
        } catch (IOException e) {
            return handleException(e, node);
        }

        return refs.toArray();
    }

    case ADDITIONALREFS: {
        List<RepositoryTreeNode<Ref>> refs = new ArrayList<RepositoryTreeNode<Ref>>();
        try {
            for (Entry<String, Ref> refEntry : repo.getRefDatabase().getRefs(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 (IOException e) {
            return handleException(e, node);
        }
        return refs.toArray();
    }

    case REMOTES: {
        List<RepositoryTreeNode<String>> remotes = new ArrayList<RepositoryTreeNode<String>>();

        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<RepositoryTreeNode<? extends Object>>();

        nodeList.add(new BranchesNode(node, repo));
        nodeList.add(new TagsNode(node, repo));
        nodeList.add(new AdditionalRefsNode(node, repo));
        nodeList.add(new WorkingDirNode(node, repo));
        nodeList.add(new RemotesNode(node, repo));

        return nodeList.toArray();
    }

    case WORKINGDIR: {
        List<RepositoryTreeNode<File>> children = new ArrayList<RepositoryTreeNode<File>>();

        if (node.getRepository().isBare())
            return children.toArray();
        File workingDir = repo.getWorkTree();
        if (workingDir == null || !workingDir.exists())
            return children.toArray();

        File[] childFiles = workingDir.listFiles();
        Arrays.sort(childFiles, new Comparator<File>() {
            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<RepositoryTreeNode<File>>();

        File parent = ((File) node.getObject());

        File[] childFiles = parent.listFiles();
        Arrays.sort(childFiles, new Comparator<File>() {
            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<RepositoryTreeNode<String>>();

        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++;

        // show push if either a fetch or push URI is specified and
        // at least one push specification
        if (uriCount > 0 && !rc.getPushRefSpecs().isEmpty()) {
            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(), firstUri.toPrivateString() + "...")); //$NON-NLS-1$
        }
        return children.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 ADDITIONALREF:
        return null;

    }

    return null;

}