Search in sources :

Example 11 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class ProjectReferenceImporterTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    testRepository = new TestRepository(gitDir);
    repository = testRepository.getRepository();
    RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    util.addConfiguredRepository(repository.getDirectory());
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) Before(org.junit.Before)

Example 12 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil 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)

Example 13 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class ProjectReferenceImporterTest method tearDown.

@Override
@After
public void tearDown() throws Exception {
    RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    util.removeDir(repository.getDirectory());
    testRepository.dispose();
    repository = null;
    super.tearDown();
}
Also used : RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) After(org.junit.After)

Example 14 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class GitLabels method getStyledLabel.

/**
 * Computes detailed repository label that consists of repository name,
 * state, checked-out branch and it's status (returned by
 * {@linkplain #formatBranchTrackingStatus(BranchTrackingStatus)})
 *
 * @param repository
 * @return a styled string for the repository
 * @throws IOException
 */
@NonNull
public static StyledString getStyledLabel(@NonNull Repository repository) throws IOException {
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
    StyledString string = getChangedPrefix(repository);
    string.append(repositoryUtil.getRepositoryName(repository));
    String branch = repositoryUtil.getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);
        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = GitLabels.formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }
        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            // $NON-NLS-1$
            string.append(" - ", StyledString.DECORATIONS_STYLER);
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }
    return string;
}
Also used : BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) RepositoryState(org.eclipse.jgit.lib.RepositoryState) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) NonNull(org.eclipse.jgit.annotations.NonNull)

Example 15 with RepositoryUtil

use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.

the class SubmoduleUpdateOperation method execute.

@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
            SubMonitor progress = SubMonitor.convert(pm, 4);
            progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_updating, util.getRepositoryName(repository)));
            Git git = Git.wrap(repository);
            Collection<String> updated = null;
            try {
                SubmoduleInitCommand init = git.submoduleInit();
                for (String path : paths) init.addPath(path);
                init.call();
                progress.worked(1);
                SubmoduleUpdateCommand update = git.submoduleUpdate();
                for (String path : paths) update.addPath(path);
                update.setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(2)));
                MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                if (strategy != null) {
                    update.setStrategy(strategy);
                }
                update.setCallback(new CloneCommand.Callback() {

                    @Override
                    public void initializedSubmodules(Collection<String> submodules) {
                    // Nothing to do
                    }

                    @Override
                    public void cloningSubmodule(String path) {
                        progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_cloning, util.getRepositoryName(repository), path));
                    }

                    @Override
                    public void checkingOut(AnyObjectId commit, String path) {
                    // Nothing to do
                    }
                });
                updated = update.call();
                SubMonitor refreshMonitor = progress.newChild(1).setWorkRemaining(updated.size());
                for (String path : updated) {
                    Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
                    if (subRepo != null) {
                        ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), refreshMonitor.newChild(1));
                    } else {
                        refreshMonitor.worked(1);
                    }
                }
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (IOException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } finally {
                if (updated != null && !updated.isEmpty()) {
                    repository.notifyIndexChanged();
                }
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) SubmoduleUpdateCommand(org.eclipse.jgit.api.SubmoduleUpdateCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IOException(java.io.IOException) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) SubmoduleInitCommand(org.eclipse.jgit.api.SubmoduleInitCommand)

Aggregations

RepositoryUtil (org.eclipse.egit.core.RepositoryUtil)16 File (java.io.File)8 IOException (java.io.IOException)6 IPath (org.eclipse.core.runtime.IPath)6 Path (org.eclipse.core.runtime.Path)5 Repository (org.eclipse.jgit.lib.Repository)4 IProject (org.eclipse.core.resources.IProject)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 URIish (org.eclipse.jgit.transport.URIish)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 CloneOperation (org.eclipse.egit.core.op.CloneOperation)2 RepositoryNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryNode)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1