Search in sources :

Example 6 with RepositoryNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.

the class GitRepositoriesViewTestUtils method getRootItem.

public SWTBotTreeItem getRootItem(SWTBotTree tree, File repositoryFile) throws Exception {
    Repository repository = lookupRepository(repositoryFile);
    RepositoryNode root = new RepositoryNode(null, repository);
    String rootText = labelProvider.getStyledText(root).getString();
    SWTBotTreeItem rootItem = tree.getTreeItem(rootText);
    return rootItem;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)

Example 7 with RepositoryNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.

the class AbstractHistoryCommandHandler method getRefNodes.

/**
 * Utility to get a list of Refs from a commit in order to handle ambiguous
 * selections when a Ref is preferred over a commit.
 *
 * @param commit
 * @param repo
 * @param refPrefixes
 *            e.g. "refs/heads/" or ""
 * @return a list of RefNodes
 */
protected List<RefNode> getRefNodes(ObjectId commit, Repository repo, String... refPrefixes) {
    List<Ref> availableBranches = new ArrayList<>();
    List<RefNode> nodes = new ArrayList<>();
    try {
        Map<String, Ref> branches = new HashMap<>();
        for (String refPrefix : refPrefixes) {
            branches.putAll(repo.getRefDatabase().getRefs(refPrefix));
        }
        for (Ref branch : branches.values()) {
            ObjectId objectId = branch.getLeaf().getObjectId();
            if (objectId != null && objectId.equals(commit)) {
                availableBranches.add(branch);
            }
        }
        RepositoryNode repoNode = new RepositoryNode(null, repo);
        for (Ref ref : availableBranches) {
            nodes.add(new RefNode(repoNode, repo, ref));
        }
    } catch (IOException e) {
    // ignore here
    }
    return nodes;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) HashMap(java.util.HashMap) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode)

Example 8 with RepositoryNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.

the class CommitSearchPage method handleWidgetSelected.

private void handleWidgetSelected() {
    int selectionIndex = patternCombo.getSelectionIndex();
    if (selectionIndex < 0 || selectionIndex >= fPreviousSearchPatterns.size()) {
        repositoryViewer.setAllChecked(true);
        repositoryGroup.setText(getRepositoryText());
        return;
    }
    CommitSearchSettings settings = fPreviousSearchPatterns.get(selectionIndex);
    if (!patternCombo.getText().equals(settings.getTextPattern()))
        return;
    isCaseSensitiveButton.setSelection(settings.isCaseSensitive());
    isRegExButton.setSelection(settings.isRegExSearch());
    patternCombo.setText(settings.getTextPattern());
    patternFieldContentAssist.setEnabled(settings.isRegExSearch());
    searchAuthorButton.setSelection(settings.isMatchAuthor());
    searchCommitButton.setSelection(settings.isMatchCommit());
    searchCommitterButton.setSelection(settings.isMatchCommitter());
    searchMessageButton.setSelection(settings.isMatchMessage());
    searchParentsButton.setSelection(settings.isMatchParents());
    searchTreeButton.setSelection(settings.isMatchTree());
    searchAllBranchesButton.setSelection(settings.isAllBranches());
    List<RepositoryNode> repositories = new LinkedList<>();
    for (String path : settings.getRepositories()) {
        File file = new File(path);
        if (file.exists())
            try {
                RepositoryNode node = new RepositoryNode(null, org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(file));
                repositories.add(node);
            } catch (IOException ignore) {
            // Ignore and don't check
            }
    }
    repositoryViewer.setCheckedElements(repositories.toArray());
    repositoryGroup.setText(getRepositoryText());
}
Also used : IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) File(java.io.File) LinkedList(java.util.LinkedList)

Example 9 with RepositoryNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.

the class SelectionForViewsTest method before.

@Before
public void before() throws Exception {
    localRepositoryDir = createProjectAndCommitToRepository();
    remoteRepositoryDir = createRemoteRepository(localRepositoryDir);
    URIish uri = new URIish("file:///" + remoteRepositoryDir.getPath());
    File workdir = new File(getTestDirectory(), "ClonedRepo");
    CloneOperation op = new CloneOperation(uri, true, null, workdir, "refs/heads/master", "origin", 0);
    op.run(null);
    clonedRepositoryDir = new File(workdir, Constants.DOT_GIT);
    RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();
    repoUtil.addConfiguredRepository(localRepositoryDir);
    repoUtil.addConfiguredRepository(clonedRepositoryDir);
    // it's bare
    repoUtil.addConfiguredRepository(remoteRepositoryDir);
    stagingView = TestUtil.showView(StagingView.VIEW_ID);
    reflogView = TestUtil.showView(ReflogView.VIEW_ID);
    rebaseInteractiveView = TestUtil.showView(RebaseInteractiveView.VIEW_ID);
    repoView = TestUtil.showView(RepositoriesView.VIEW_ID);
    RepositoriesView repos = (RepositoriesView) repoView.getViewReference().getView(false);
    repos.setReactOnSelection(true);
    historyView = TestUtil.showHistoryView();
    IHistoryView history = (IHistoryView) historyView.getViewReference().getView(false);
    ((GenericHistoryView) history).setLinkingEnabled(true);
    // Ensure that the git history page is active
    Exception[] exception = { null };
    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        try {
            history.showHistoryFor(new RepositoryNode(null, lookupRepository(localRepositoryDir)), true);
        } catch (Exception e) {
            exception[0] = e;
        }
    });
    if (exception[0] != null) {
        throw exception[0];
    }
    waitForRefreshes();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) GenericHistoryView(org.eclipse.team.internal.ui.history.GenericHistoryView) RepositoriesView(org.eclipse.egit.ui.internal.repository.RepositoriesView) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) File(java.io.File) IHistoryView(org.eclipse.team.ui.history.IHistoryView) CloneOperation(org.eclipse.egit.core.op.CloneOperation) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Before(org.junit.Before)

Example 10 with RepositoryNode

use of org.eclipse.egit.ui.internal.repository.tree.RepositoryNode in project egit by eclipse.

the class RemoveCommand method removeRepository.

/**
 * Remove or delete the repository
 *
 * @param event
 * @param delete
 *            if <code>true</code>, the repository will be deleted from disk
 */
protected void removeRepository(final ExecutionEvent event, final boolean delete) {
    IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
    IWorkbenchSiteProgressService service = null;
    if (serviceLocator != null) {
        service = CommonUtils.getService(serviceLocator, IWorkbenchSiteProgressService.class);
    }
    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return;
    }
    boolean deleteWorkingDir = false;
    boolean removeProjects = false;
    final List<IProject> projectsToDelete = findProjectsToDelete(selectedNodes);
    if (delete) {
        if (selectedNodes.size() > 1) {
            return;
        } else if (selectedNodes.size() == 1) {
            Repository repository = selectedNodes.get(0).getObject();
            if (repository.isBare()) {
                // simple confirm dialog
                String title = UIText.RemoveCommand_ConfirmDeleteBareRepositoryTitle;
                String message = NLS.bind(UIText.RemoveCommand_ConfirmDeleteBareRepositoryMessage, repository.getDirectory().getPath());
                if (!MessageDialog.openConfirm(getShell(event), title, message))
                    return;
            } else {
                // confirm dialog with check box
                // "delete also working directory"
                DeleteRepositoryConfirmDialog dlg = new DeleteRepositoryConfirmDialog(getShell(event), repository, projectsToDelete);
                if (dlg.open() != Window.OK)
                    return;
                deleteWorkingDir = dlg.shouldDeleteWorkingDir();
                removeProjects = dlg.shouldRemoveProjects();
            }
        }
    } else {
        if (!projectsToDelete.isEmpty()) {
            final boolean[] confirmedCanceled = new boolean[] { false, false };
            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        confirmedCanceled[0] = confirmProjectDeletion(projectsToDelete, event);
                    } catch (OperationCanceledException e) {
                        confirmedCanceled[1] = true;
                    }
                }
            });
            if (confirmedCanceled[1])
                return;
            removeProjects = confirmedCanceled[0];
        }
    }
    final boolean deleteWorkDir = deleteWorkingDir;
    final boolean removeProj = removeProjects;
    Job job = new WorkspaceJob(UIText.RemoveCommand_RemoveRepositoriesJob) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage);
            if (removeProj) {
                // confirmed deletion
                deleteProjects(deleteWorkDir, projectsToDelete, monitor);
            }
            for (RepositoryNode node : selectedNodes) {
                util.removeDir(node.getRepository().getDirectory());
            }
            if (delete) {
                try {
                    deleteRepositoryContent(selectedNodes, deleteWorkDir);
                } catch (IOException e) {
                    return Activator.createErrorStatus(e.getMessage(), e);
                }
            }
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    for (RepositoryNode node : selectedNodes) {
                        node.clear();
                    }
                }
            });
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.REPOSITORY_DELETE.equals(family))
                return true;
            else
                return super.belongsTo(family);
        }
    };
    if (service == null) {
        job.schedule();
    } else {
        service.schedule(job);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IServiceLocator(org.eclipse.ui.services.IServiceLocator) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ExecutionException(org.eclipse.core.commands.ExecutionException) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Aggregations

RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)27 Repository (org.eclipse.jgit.lib.Repository)18 File (java.io.File)7 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 LocalNode (org.eclipse.egit.ui.internal.repository.tree.LocalNode)4 TagsNode (org.eclipse.egit.ui.internal.repository.tree.TagsNode)4 Before (org.junit.Before)4 URISyntaxException (java.net.URISyntaxException)3 RepositoriesViewLabelProvider (org.eclipse.egit.ui.internal.repository.RepositoriesViewLabelProvider)3 BranchesNode (org.eclipse.egit.ui.internal.repository.tree.BranchesNode)3 RefNode (org.eclipse.egit.ui.internal.repository.tree.RefNode)3 RemoteTrackingNode (org.eclipse.egit.ui.internal.repository.tree.RemoteTrackingNode)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 List (java.util.List)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2