Search in sources :

Example 11 with RepositoryNode

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

the class RemoveCommand method deleteRepositoryContent.

private void deleteRepositoryContent(final List<RepositoryNode> selectedNodes, final boolean deleteWorkDir) throws IOException {
    for (RepositoryNode node : selectedNodes) {
        Repository repo = node.getRepository();
        File workTree = deleteWorkDir && !repo.isBare() ? repo.getWorkTree() : null;
        if (workTree != null) {
            File[] files = workTree.listFiles();
            if (files != null)
                for (File file : files) {
                    if (isTracked(file, repo))
                        FileUtils.delete(file, FileUtils.RECURSIVE | FileUtils.RETRY);
                }
        }
        repo.close();
        if (!repo.isBare())
            closeSubmoduleRepositories(repo);
        FileUtils.delete(repo.getDirectory(), FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
        if (workTree != null) {
            // parent repository
            if (node.getParent() != null && node.getParent().getType() == RepositoryTreeNodeType.SUBMODULES) {
                FileUtils.delete(workTree, FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
                node.getParent().getRepository().notifyIndexChanged();
            }
            // Delete if empty working directory
            String[] files = workTree.list();
            boolean isWorkingDirEmpty = files != null && files.length == 0;
            if (isWorkingDirEmpty)
                FileUtils.delete(workTree, FileUtils.RETRY | FileUtils.SKIP_MISSING);
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) File(java.io.File)

Example 12 with RepositoryNode

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

the class GarbageCollectCommand method execute.

/**
 * Execute garbage collection
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
        if (selectedNodes.isEmpty())
            return null;
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Collecting Garbage...") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            for (RepositoryNode node : selectedNodes) {
                Repository repo = node.getRepository();
                String name = MessageFormat.format(UIText.GarbageCollectCommand_jobTitle, getRepositoryName(repo));
                this.setName(name);
                final GarbageCollectOperation op = new GarbageCollectOperation(repo);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(MessageFormat.format(UIText.GarbageCollectCommand_failed, repo), e);
                }
            }
            return Status.OK_STATUS;
        }
    };
    IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
    if (serviceLocator != null) {
        IWorkbenchSiteProgressService service = CommonUtils.getService(serviceLocator, IWorkbenchSiteProgressService.class);
        service.schedule(job);
    } else {
        job.schedule();
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) GarbageCollectOperation(org.eclipse.egit.core.op.GarbageCollectOperation) IServiceLocator(org.eclipse.ui.services.IServiceLocator) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) ExecutionException(org.eclipse.core.commands.ExecutionException) Job(org.eclipse.core.runtime.jobs.Job)

Example 13 with RepositoryNode

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

the class GitSelectRepositoryPage method refreshRepositoryList.

private void refreshRepositoryList() {
    List<?> dirsBefore = (List<?>) tv.getInput();
    List<String> dirsAfter = util.getConfiguredRepositories();
    if (dirsBefore == null) {
        dirsBefore = Collections.emptyList();
    }
    if (!dirsBefore.containsAll(dirsAfter)) {
        IStructuredSelection previousSelection = (IStructuredSelection) tv.getSelection();
        tv.setInput(dirsAfter);
        for (String dir : dirsAfter) {
            if (!dirsBefore.contains(dir)) {
                try {
                    Repository newRepository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(new File(dir));
                    if (!allowBare && newRepository.isBare()) {
                        // Re-set to previous selection, if any
                        if (!previousSelection.isEmpty()) {
                            tv.setSelection(previousSelection);
                        }
                    } else {
                        RepositoryNode node = new RepositoryNode(null, newRepository);
                        tv.setSelection(new StructuredSelection(node));
                    }
                } catch (IOException e1) {
                    Activator.handleError(e1.getMessage(), e1, false);
                }
                break;
            }
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) File(java.io.File)

Example 14 with RepositoryNode

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

the class GitSelectRepositoryPage method setVisible.

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    if (visible && tv.getSelection().isEmpty()) {
        // check in the dialog settings if a repository was selected before
        // and select it if nothing else is selected
        String repoDir = settings.get(LAST_SELECTED_REPO_PREF);
        if (repoDir != null)
            for (TreeItem item : tv.getTree().getItems()) {
                RepositoryNode node = (RepositoryNode) item.getData();
                if (node.getRepository().getDirectory().getPath().equals(repoDir))
                    tv.setSelection(new StructuredSelection(node));
            }
    } else {
        // save selection in dialog settings
        Object element = ((IStructuredSelection) tv.getSelection()).getFirstElement();
        if (element instanceof RepositoryNode)
            settings.put(LAST_SELECTED_REPO_PREF, ((RepositoryNode) element).getRepository().getDirectory().getPath());
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TreeItem(org.eclipse.swt.widgets.TreeItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)

Example 15 with RepositoryNode

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

the class RepositoriesViewContentProvider method getElements.

@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
    List<RepositoryTreeNode> nodes = new ArrayList<>();
    List<String> directories = new ArrayList<>();
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    if (inputElement instanceof Collection) {
        for (Iterator it = ((Collection) inputElement).iterator(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof RepositoryTreeNode)
                nodes.add((RepositoryTreeNode) next);
            else if (next instanceof String)
                directories.add((String) next);
        }
    } else if (inputElement instanceof IWorkspaceRoot) {
        directories.addAll(repositoryUtil.getConfiguredRepositories());
    }
    for (String directory : directories) {
        try {
            File gitDir = new File(directory);
            if (gitDir.exists()) {
                RepositoryNode rNode = new RepositoryNode(null, repositoryCache.lookupRepository(gitDir));
                nodes.add(rNode);
            } else
                repositoryUtil.removeDir(gitDir);
        } catch (IOException e) {
        // ignore for now
        }
    }
    Collections.sort(nodes);
    return nodes.toArray();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryNode) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Iterator(java.util.Iterator) Collection(java.util.Collection) RevObject(org.eclipse.jgit.revwalk.RevObject) File(java.io.File)

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