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);
}
}
}
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;
}
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;
}
}
}
}
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());
}
}
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();
}
Aggregations