Example usage for org.eclipse.jgit.lib Repository isBare

List of usage examples for org.eclipse.jgit.lib Repository isBare

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository isBare.

Prototype

public boolean isBare() 

Source Link

Document

Whether this repository is bare

Usage

From source file:org.eclipse.egit.ui.internal.repository.tree.command.RemoveCommand.java

License:Open Source License

/**
 * Remove or delete the repository/*from  w  w w . j av  a2  s . c o m*/
 *
 * @param event
 * @param delete
 *            if <code>true</code>, the repository will be deleted from disk
 */
protected void removeRepository(final ExecutionEvent event, final boolean delete) {
    IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
    IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) activeSite
            .getService(IWorkbenchSiteProgressService.class);

    // get selected nodes
    final List<RepositoryNode> selectedNodes;
    try {
        selectedNodes = getSelectedNodes(event);
    } catch (ExecutionException e) {
        Activator.handleError(e.getMessage(), e, true);
        return;
    }

    if (delete) {
        String title = UIText.RemoveCommand_DeleteConfirmTitle;
        if (selectedNodes.size() > 1) {
            String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmSingleMessage,
                    Integer.valueOf(selectedNodes.size()));
            if (!MessageDialog.openConfirm(getShell(event), title, message))
                return;
        } else if (selectedNodes.size() == 1) {
            String name = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil()
                    .getRepositoryName(selectedNodes.get(0).getObject());
            String message = NLS.bind(UIText.RemoveCommand_DeleteConfirmMultiMessage, name);
            if (!MessageDialog.openConfirm(getShell(event), title, message))
                return;
        }
    }

    Job job = new Job("Remove Repositories Job") { //$NON-NLS-1$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final List<IProject> projectsToDelete = new ArrayList<IProject>();

            monitor.setTaskName(UIText.RepositoriesView_DeleteRepoDeterminProjectsMessage);

            for (RepositoryNode node : selectedNodes) {
                if (node.getRepository().isBare())
                    continue;
                File workDir = node.getRepository().getWorkTree();
                final IPath wdPath = new Path(workDir.getAbsolutePath());
                for (IProject prj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                    if (monitor.isCanceled())
                        return Status.OK_STATUS;
                    if (wdPath.isPrefixOf(prj.getLocation())) {
                        projectsToDelete.add(prj);
                    }
                }
            }

            final boolean[] confirmedCanceled = new boolean[] { false, false };

            if (!projectsToDelete.isEmpty()) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        try {
                            confirmedCanceled[0] = confirmProjectDeletion(projectsToDelete, event);
                        } catch (OperationCanceledException e) {
                            confirmedCanceled[1] = true;
                        }
                    }
                });
            }
            if (confirmedCanceled[1]) {
                // canceled: return
                return Status.OK_STATUS;
            }
            if (confirmedCanceled[0]) {
                // confirmed deletion
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    public void run(IProgressMonitor actMonitor) throws CoreException {

                        for (IProject prj : projectsToDelete)
                            prj.delete(false, false, actMonitor);
                    }
                };

                try {
                    ResourcesPlugin.getWorkspace().run(wsr, ResourcesPlugin.getWorkspace().getRoot(),
                            IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e1) {
                    Activator.logError(e1.getMessage(), e1);
                }
            }
            for (RepositoryNode node : selectedNodes) {
                util.removeDir(node.getRepository().getDirectory());
            }

            if (delete) {
                try {
                    for (RepositoryNode node : selectedNodes) {
                        Repository repo = node.getRepository();
                        if (!repo.isBare())
                            FileUtils.delete(repo.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY);
                        FileUtils.delete(repo.getDirectory(),
                                FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
                    }
                } catch (IOException e) {
                    return Activator.createErrorStatus(e.getMessage(), e);
                }
            }
            return Status.OK_STATUS;
        }
    };

    service.schedule(job);
}

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

License:Open Source License

/**
 * TODO javadoc missing//www .j  av  a 2 s.  co  m
 */
@SuppressWarnings("unchecked")
public IStructuredSelection findSelection(IEditorInput anInput) {
    if (!(anInput instanceof IURIEditorInput)) {
        return null;
    }

    URI uri = ((IURIEditorInput) anInput).getURI();

    if (!uri.getScheme().equals("file")) //$NON-NLS-1$
        return null;

    File file = new File(uri.getPath());

    if (!file.exists())
        return null;

    RepositoryUtil config = Activator.getDefault().getRepositoryUtil();

    List<String> repos = config.getConfiguredRepositories();
    for (String repo : repos) {
        Repository repository;
        try {
            repository = new FileRepository(new File(repo));
        } catch (IOException e) {
            continue;
        }
        if (repository.isBare())
            continue;
        if (file.getPath().startsWith(repository.getWorkTree().getPath())) {
            RepositoriesViewContentProvider cp = new RepositoriesViewContentProvider();

            RepositoryNode repoNode = new RepositoryNode(null, repository);
            RepositoryTreeNode result = null;

            for (Object child : cp.getChildren(repoNode)) {
                if (child instanceof WorkingDirNode) {
                    result = (WorkingDirNode) child;
                    break;
                }
            }

            if (result == null)
                return null;

            IPath remainingPath = new Path(
                    file.getPath().substring(repository.getWorkTree().getPath().length()));
            for (String segment : remainingPath.segments()) {
                for (Object child : cp.getChildren(result)) {
                    RepositoryTreeNode<File> fileNode;
                    try {
                        fileNode = (RepositoryTreeNode<File>) child;
                    } catch (ClassCastException e) {
                        return null;
                    }
                    if (fileNode.getObject().getName().equals(segment)) {
                        result = fileNode;
                        break;
                    }
                }
            }

            return new StructuredSelection(result);
        }
    }
    return null;
}

From source file:org.eclipse.egit.ui.internal.resources.ResourceStateFactory.java

License:Open Source License

/**
 * Returns the {@link IndexDiffData} for a given {@link Repository}.
 *
 * @param repository/*  w  ww . j a  va  2  s  .c  o m*/
 *            to get the index diff data from
 * @return the IndexDiffData, or {@code null} if none.
 */
@Nullable
private IndexDiffData getIndexDiffDataOrNull(@Nullable Repository repository) {
    if (repository == null) {
        return null;
    } else if (repository.isBare()) {
        // For bare repository just return empty data
        return new IndexDiffData();
    }
    IndexDiffCacheEntry diffCacheEntry = Activator.getDefault().getIndexDiffCache()
            .getIndexDiffCacheEntry(repository);
    if (diffCacheEntry == null) {
        return null;
    }
    return diffCacheEntry.getIndexDiff();
}

From source file:org.eclipse.egit.ui.internal.resources.ResourceStateFactory.java

License:Open Source License

/**
 * Computes an {@link IResourceState} for the given {@link FileSystemItem}
 * from the given {@link IndexDiffData}.
 *
 * @param indexDiffData//from  ww  w .  j  a  v a  2 s  . co m
 *            to compute the state from
 * @param file
 *            to get the state of
 * @return the state
 */
@NonNull
private IResourceState get(@NonNull IndexDiffData indexDiffData, @NonNull FileSystemItem file) {
    IPath path = file.getAbsolutePath();
    if (path == null) {
        return UNKNOWN_STATE;
    }
    Repository repository = file.getRepository();
    if (repository == null || repository.isBare()) {
        return UNKNOWN_STATE;
    }
    File workTree = repository.getWorkTree();
    String repoRelativePath = path.makeRelativeTo(new org.eclipse.core.runtime.Path(workTree.getAbsolutePath()))
            .toString();
    if (repoRelativePath.equals(path.toString())) {
        // Could not be made relative.
        return UNKNOWN_STATE;
    }
    ResourceState result = new ResourceState();
    if (file.isContainer()) {
        if (!repoRelativePath.endsWith("/")) { //$NON-NLS-1$
            repoRelativePath += '/';
        }
        if (ResourceUtil.isSymbolicLink(repository, repoRelativePath)) {
            // The Eclipse resource model handles a symlink to a folder like
            // the container it refers to but git status handles the symlink
            // source like a special file.
            extractFileProperties(indexDiffData, repoRelativePath, result);
        } else {
            extractContainerProperties(indexDiffData, repoRelativePath, file, result);
        }
    } else {
        extractFileProperties(indexDiffData, repoRelativePath, result);
    }
    return result;
}

From source file:org.eclipse.egit.ui.internal.sharing.RepoComboContentProvider.java

License:Open Source License

public Object[] getElements(Object inputElement) {
    List<Repository> nonBareRepos = new ArrayList<Repository>();
    for (String dir : util.getConfiguredRepositories()) {
        Repository repo;
        try {// w ww.  j  av a2  s.c o  m
            repo = cache.lookupRepository(new File(dir));
        } catch (IOException e1) {
            continue;
        }
        if (repo.isBare())
            continue;
        nonBareRepos.add(repo);
    }
    return nonBareRepos.toArray();
}

From source file:org.eclipse.egit.ui.internal.staging.StagingView.java

License:Open Source License

private boolean isValidRepo(final Repository repository) {
    return repository != null && !repository.isBare() && repository.getWorkTree().exists()
            && org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil().contains(repository);
}

From source file:org.jboss.as.server.controller.git.GitRepository.java

License:Apache License

public GitRepository(Repository repository) {
    this.repository = repository;
    this.ignored = Collections.emptySet();
    this.defaultRemoteRepository = DEFAULT_REMOTE_NAME;
    this.branch = MASTER;
    if (repository.isBare()) {
        this.basePath = repository.getDirectory().toPath();
    } else {/*w  ww  .  j a  v  a2 s.  c om*/
        this.basePath = repository.getDirectory().toPath().getParent();
    }
    ServerLogger.ROOT_LOGGER.usingGit();
}

From source file:org.kercoin.magrit.core.utils.GitUtils.java

License:Open Source License

public void addRemote(Repository toConfigure, String name, Repository remoteRepo) throws IOException {
    final String refSpec = String.format(REF_SPEC_PATTERN, name);
    File dest = remoteRepo.getDirectory();
    if (!remoteRepo.isBare()) {
        dest = dest.getParentFile();//  www  .j a  v a  2 s .  co  m
    }
    synchronized (toConfigure) {
        toConfigure.getConfig().setString("remote", name, "fetch", refSpec);
        toConfigure.getConfig().setString("remote", name, "url", dest.getAbsolutePath());
        // write down configuration in .git/config
        toConfigure.getConfig().save();
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.GitCommand.java

License:Apache License

/**
 * Check if the repository is bare, if not throws an {@link IllegalStateException}
 * @param repository Git Repository you need to check
 *///w w w. j  av a2s  .  co  m
protected void isBare(Repository repository) {
    if (!repository.isBare()) {
        throw new IllegalStateException("You cannot squash/rebase in a non BARE repository");
    }
}