Search in sources :

Example 26 with RepositoryMapping

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

the class GitVariableResolver method getGitBranch.

private String getGitBranch(String argument) throws CoreException {
    IResource res = getResource(argument);
    RepositoryMapping mapping = RepositoryMapping.getMapping(res);
    if (mapping != null)
        try {
            return mapping.getRepository().getBranch();
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage()));
        }
    else
        // $NON-NLS-1$
        return "";
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) IResource(org.eclipse.core.resources.IResource)

Example 27 with RepositoryMapping

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

the class TrackUntrackOperationTest method assertTrackedState.

@SuppressWarnings("boxing")
private void assertTrackedState(IFile[] fileArr, boolean expectedState) throws IOException {
    DirCache cache = repository1.getRepository().readDirCache();
    for (IFile file : fileArr) {
        RepositoryMapping rm = RepositoryMapping.getMapping(file);
        String fileDir = rm.getRepoRelativePath(file);
        boolean tracked = cache.findEntry(fileDir) > -1;
        assertEquals("Wrong tracking state", expectedState, tracked);
    }
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) IFile(org.eclipse.core.resources.IFile) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 28 with RepositoryMapping

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

the class GitResourceDeltaVisitor method visit.

@Override
public boolean visit(IResourceDelta delta) throws CoreException {
    final IResource resource = delta.getResource();
    if (resource.getType() == IResource.ROOT) {
        return true;
    }
    if (resource.getType() == IResource.PROJECT) {
        if (delta.getKind() == IResourceDelta.REMOVED) {
            IPath loc = deletedProjects.remove(resource);
            if (loc != null) {
                projectDeleted |= !loc.toFile().isDirectory();
            }
            return false;
        }
        // Git revision control or from a different repository
        if (!ResourceUtil.isSharedWithGit(resource)) {
            // Ignore the change for project and its children
            return false;
        }
        GitProjectData gitData = GitProjectData.get((IProject) resource);
        if (gitData == null) {
            return false;
        }
        RepositoryMapping mapping = gitData.getRepositoryMapping(resource);
        if (mapping == null || !gitData.hasInnerRepositories() && mapping.getRepository() != repository) {
            return false;
        }
        // continue with children
        return true;
    }
    Repository repositoryOfResource = null;
    if (resource.isLinked()) {
        IPath location = resource.getLocation();
        if (location == null) {
            return false;
        }
        repositoryOfResource = ResourceUtil.getRepository(location);
        // in the same repository
        if (repository != repositoryOfResource) {
            return false;
        }
    } else {
        repositoryOfResource = ResourceUtil.getRepository(resource);
    }
    if (resource.getType() == IResource.FOLDER) {
        GitProjectData gitData = GitProjectData.get(resource.getProject());
        if (gitData == null) {
            return false;
        }
        if (repositoryOfResource == null || !gitData.isProtected(resource) && repositoryOfResource != repository) {
            return false;
        }
        if (delta.getKind() == IResourceDelta.ADDED) {
            IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
            if (repoRelativePath == null) {
                return false;
            }
            if (!repoRelativePath.isEmpty()) {
                // $NON-NLS-1$
                String path = repoRelativePath.toPortableString() + "/";
                if (isIgnoredInOldIndex(path)) {
                    // keep going to catch .gitignore files.
                    return true;
                }
                filesToUpdate.add(path);
                resourcesToUpdate.add(resource);
            }
        }
        // continue with children
        return true;
    }
    if (repositoryOfResource != repository) {
        return false;
    }
    if (!isInteresting(delta)) {
        return false;
    }
    if (resource.getName().equals(Constants.DOT_GIT_IGNORE)) {
        gitIgnoreChanged = true;
        return false;
    }
    IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
    if (repoRelativePath == null) {
        resourcesToUpdate.add(resource);
        return true;
    }
    String path = repoRelativePath.toPortableString();
    if (isIgnoredInOldIndex(path)) {
        // change: ignore the delta to avoid unnecessary index updates
        return false;
    }
    filesToUpdate.add(path);
    resourcesToUpdate.add(resource);
    return true;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IResource(org.eclipse.core.resources.IResource)

Example 29 with RepositoryMapping

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

the class GitMoveDeleteHook method moveFile.

@Override
public boolean moveFile(final IResourceTree tree, final IFile srcf, final IFile dstf, final int updateFlags, final IProgressMonitor monitor) {
    final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
    if (!force && !tree.isSynchronized(srcf, IResource.DEPTH_ZERO))
        return false;
    final RepositoryMapping srcm = RepositoryMapping.getMapping(srcf);
    if (srcm == null)
        return false;
    final RepositoryMapping dstm = RepositoryMapping.getMapping(dstf);
    DirCache sCache = null;
    try {
        sCache = srcm.getRepository().lockDirCache();
        final String sPath = srcm.getRepoRelativePath(srcf);
        final DirCacheEntry sEnt = sCache.getEntry(sPath);
        if (sEnt == null)
            return FINISH_FOR_ME;
        if (!sEnt.isMerged()) {
            tree.failed(new Status(IStatus.WARNING, Activator.getPluginId(), CoreText.MoveDeleteHook_unmergedFileError));
            return I_AM_DONE;
        }
        if (org.eclipse.egit.core.Activator.autoStageMoves()) {
            final DirCacheEditor sEdit = sCache.editor();
            sEdit.add(new DirCacheEditor.DeletePath(sEnt));
            if (dstm != null && dstm.getRepository() == srcm.getRepository()) {
                final String dPath = srcm.getRepoRelativePath(dstf);
                sEdit.add(new DirCacheEditor.PathEdit(dPath) {

                    @Override
                    public void apply(final DirCacheEntry dEnt) {
                        dEnt.copyMetaData(sEnt);
                    }
                });
            }
            if (!sEdit.commit()) {
                tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
            }
        }
        tree.standardMoveFile(srcf, dstf, updateFlags, monitor);
    } catch (IOException e) {
        tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
    } finally {
        if (sCache != null)
            sCache.unlock();
    }
    return I_AM_DONE;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DirCache(org.eclipse.jgit.dircache.DirCache) DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor) IOException(java.io.IOException)

Example 30 with RepositoryMapping

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

the class GitMoveDeleteHook method moveFolder.

@Override
public boolean moveFolder(final IResourceTree tree, final IFolder srcf, final IFolder dstf, final int updateFlags, final IProgressMonitor monitor) {
    final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
    if (!force && !tree.isSynchronized(srcf, IResource.DEPTH_ZERO))
        return false;
    final RepositoryMapping srcm = RepositoryMapping.getMapping(srcf);
    if (srcm == null)
        return false;
    final RepositoryMapping dstm = RepositoryMapping.getMapping(dstf);
    try {
        final String sPath = srcm.getRepoRelativePath(srcf);
        if (dstm != null && dstm.getRepository() == srcm.getRepository()) {
            MoveResult result = null;
            if (org.eclipse.egit.core.Activator.autoStageMoves()) {
                // $NON-NLS-1$
                final String dPath = srcm.getRepoRelativePath(dstf) + "/";
                result = moveIndexContent(dPath, srcm, sPath);
            } else {
                result = checkUnmergedPaths(srcm, sPath);
            }
            switch(result) {
                case SUCCESS:
                    break;
                case FAILED:
                    tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
                    return I_AM_DONE;
                case UNTRACKED:
                    // we are not responsible for moving untracked files
                    return FINISH_FOR_ME;
                case UNMERGED:
                    tree.failed(new Status(IStatus.WARNING, Activator.getPluginId(), CoreText.MoveDeleteHook_unmergedFileInFolderError));
                    return I_AM_DONE;
            }
        }
        tree.standardMoveFolder(srcf, dstf, updateFlags, monitor);
    } catch (IOException e) {
        tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException)

Aggregations

RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)87 Repository (org.eclipse.jgit.lib.Repository)40 IResource (org.eclipse.core.resources.IResource)31 IProject (org.eclipse.core.resources.IProject)23 IPath (org.eclipse.core.runtime.IPath)20 IOException (java.io.IOException)18 File (java.io.File)17 CoreException (org.eclipse.core.runtime.CoreException)15 IFile (org.eclipse.core.resources.IFile)12 Path (org.eclipse.core.runtime.Path)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 GitProjectData (org.eclipse.egit.core.project.GitProjectData)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 HashMap (java.util.HashMap)5