Example usage for org.eclipse.jgit.lib IndexDiff getMissing

List of usage examples for org.eclipse.jgit.lib IndexDiff getMissing

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib IndexDiff getMissing.

Prototype

public Set<String> getMissing() 

Source Link

Document

Get list of files in index, but not filesystem

Usage

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepository.java

License:Open Source License

public boolean isDirty(boolean ignoreUntracked) throws GitRepositoryException {
    try {//from  w w  w .  j av a 2 s .  co m
        FileTreeIterator workTreeIterator = new FileTreeIterator(this.repository);
        IndexDiff indexDiff = new IndexDiff(this.repository, this.getHeadObject(), workTreeIterator);
        indexDiff.diff();

        if (!ignoreUntracked && !indexDiff.getUntracked().isEmpty()) {
            return true;
        }

        return !(indexDiff.getAdded().isEmpty() && indexDiff.getChanged().isEmpty()
                && indexDiff.getRemoved().isEmpty() && indexDiff.getMissing().isEmpty()
                && indexDiff.getModified().isEmpty() && indexDiff.getConflicting().isEmpty());

    } catch (IOException e) {
        throw new GitRepositoryException("Could not create repository diff.", e);
    }
}

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepositoryTest.java

License:Open Source License

@Test
public void testClean() throws Exception {
    IndexDiff indexDiff = this.mockIndexDiff();
    when(indexDiff.getAdded()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getChanged()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getRemoved()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getMissing()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getModified()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getConflicting()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getUntracked()).thenReturn(Collections.<String>emptySet());

    assertThat(this.repository.isDirty(false), is(false));

    verify(indexDiff).diff();/*from   w  w w .j  a va  2  s.  c o  m*/
}

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepositoryTest.java

License:Open Source License

@Test
public void testCleanIgnoreUntracked() throws Exception {
    IndexDiff indexDiff = this.mockIndexDiff();
    when(indexDiff.getAdded()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getChanged()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getRemoved()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getMissing()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getModified()).thenReturn(Collections.<String>emptySet());
    when(indexDiff.getConflicting()).thenReturn(Collections.<String>emptySet());

    assertThat(this.repository.isDirty(true), is(false));

    verify(indexDiff).diff();/*from  w ww .  j  a v  a2 s  .  c  o m*/
}

From source file:com.stormcloud.ide.api.git.GitManager.java

License:Open Source License

@Override
public IndexState getIndexState(String repository) throws GitManagerException {

    IndexState indexState = new IndexState();

    try {/*from  w ww  .  jav a2  s . c  o  m*/

        Git git = Git.open(new File(repository));

        IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository()));

        diff.diff();

        indexState.setAdded(diff.getAdded());
        indexState.setAssumeUnchanged(diff.getAssumeUnchanged());
        indexState.setChanged(diff.getChanged());
        indexState.setConflicting(diff.getConflicting());
        indexState.setIgnoredNotInIndex(diff.getIgnoredNotInIndex());
        indexState.setMissing(diff.getMissing());
        indexState.setModified(diff.getModified());
        indexState.setRemoved(diff.getRemoved());
        indexState.setUntracked(diff.getUntracked());
        indexState.setUntrackedFolders(diff.getUntrackedFolders());

    } catch (IOException e) {
        LOG.error(e);
        throw new GitManagerException(e);
    }

    return indexState;
}

From source file:com.stormcloud.ide.api.git.GitManager.java

License:Open Source License

@Override
public boolean isModified(String repository) throws GitManagerException {

    try {/*from  w  w  w .  j a  va 2  s  .c  o m*/

        Git git = Git.open(new File(repository));

        IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository()));

        diff.diff();

        if (!diff.getAdded().isEmpty()) {
            return true;
        }

        if (!diff.getChanged().isEmpty()) {
            return true;
        }

        if (!diff.getMissing().isEmpty()) {
            return true;
        }

        if (!diff.getModified().isEmpty()) {
            return true;
        }

        if (!diff.getRemoved().isEmpty()) {
            return true;
        }

        if (!diff.getUntracked().isEmpty()) {
            return true;
        }

        if (!diff.getUntrackedFolders().isEmpty()) {
            return true;
        }

    } catch (IOException e) {
        LOG.error(e);
        throw new GitManagerException(e);
    }

    return false;
}

From source file:com.stormcloud.ide.api.git.GitManager.java

License:Open Source License

@Override
public void log(String repo) throws GitManagerException {

    try {//from  ww  w .j av  a2  s. co m
        File gitDir = new File(repo + "/.git");
        LOG.info("gitDir:" + gitDir);
        Repository repository = new FileRepository(gitDir);

        WorkingTreeIterator fileTreeIterator = new FileTreeIterator(repository);

        IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator);

        boolean hasDiff = indexDiff.diff();

        LOG.info("hasDiff " + hasDiff);

        if (hasDiff) {

            for (String file : indexDiff.getAdded()) {
                LOG.info("Added " + file);
            }

            for (String file : indexDiff.getAssumeUnchanged()) {
                LOG.info("Assume Unchanged " + file);
            }

            for (String file : indexDiff.getChanged()) {
                LOG.info("Changed " + file);
            }

            for (String file : indexDiff.getConflicting()) {
                LOG.info("Conflicting " + file);
            }

            for (String file : indexDiff.getIgnoredNotInIndex()) {
                LOG.info("Ignored not in index " + file);
            }

            for (String file : indexDiff.getMissing()) {
                LOG.info("Missing " + file);
            }

            for (String file : indexDiff.getModified()) {
                LOG.info("Modified " + file);
            }

            for (String file : indexDiff.getRemoved()) {
                LOG.info("Removed " + file);
            }

            for (String file : indexDiff.getUntracked()) {
                LOG.info("Untracked " + file);
            }

            for (String file : indexDiff.getUntrackedFolders()) {
                LOG.info("Untracked Folders " + file);
            }
        }

    } catch (IOException e) {
        LOG.error(e);
        throw new GitManagerException(e);
    }

}

From source file:com.stormcloud.ide.api.git.GitManager.java

License:Open Source License

@Override
public String getStatus(String file, String userHome) throws GitManagerException {

    String tmpRelativePath = new File(file).getAbsolutePath().replaceFirst(userHome + "/projects", "")
            .replaceFirst("/", "");

    String project;/*from   w  ww . j a  va2 s  .  c o m*/

    if (tmpRelativePath.contains("/")) {

        project = tmpRelativePath.substring(0, tmpRelativePath.indexOf('/'));

    } else {

        project = tmpRelativePath;
    }

    String repository = userHome + "/projects/" + project;
    String relativePath = tmpRelativePath.replaceFirst(project, "").replaceFirst("/", "");

    String status = "unmodified";

    try {

        Git git = Git.open(new File(repository));

        IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository()));

        diff.setFilter(PathFilterGroup.createFromStrings(relativePath));

        diff.diff();

        if (!diff.getModified().isEmpty() || !diff.getChanged().isEmpty()) {
            return "modified";
        }

        if (!diff.getMissing().isEmpty() || !diff.getRemoved().isEmpty()) {
            return "missing";
        }

        if (!diff.getUntracked().isEmpty() || !diff.getUntrackedFolders().isEmpty()
                || !diff.getAdded().isEmpty()) {

            return "untracked";
        }

        if (!diff.getConflicting().isEmpty()) {
            return "conflict";
        }

        return status;

    } catch (IOException e) {
        LOG.error(e);
        throw new GitManagerException(e);
    }
}

From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffData.java

License:Open Source License

/**
 * @param indexDiff//from w w  w  . j  a  v  a  2  s  .c  o  m
 */
public IndexDiffData(IndexDiff indexDiff) {
    added = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getAdded()));
    changed = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getChanged()));
    removed = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getRemoved()));
    missing = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getMissing()));
    modified = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getModified()));
    untracked = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getUntracked()));
    untrackedFolders = Collections.unmodifiableSet(getUntrackedFolders(indexDiff));
    conflicts = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getConflicting()));
    ignored = Collections.unmodifiableSet(new HashSet<String>(indexDiff.getIgnoredNotInIndex()));
    changedResources = null;
}

From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffData.java

License:Open Source License

/**
 * This constructor merges the existing IndexDiffData object baseDiff with a
 * new IndexDiffData object that was calculated for a subset of files
 * (changedFiles).//from w w  w.j  av a  2 s . co m
 *
 * @param baseDiff
 * @param changedFiles
 *            collection of changed files / folders. folders must end with /
 * @param changedResources
 * @param diffForChangedFiles
 */
public IndexDiffData(IndexDiffData baseDiff, Collection<String> changedFiles,
        Collection<IResource> changedResources, IndexDiff diffForChangedFiles) {
    this.changedResources = Collections.unmodifiableCollection(new HashSet<IResource>(changedResources));
    Set<String> added2 = new HashSet<String>(baseDiff.getAdded());
    Set<String> changed2 = new HashSet<String>(baseDiff.getChanged());
    Set<String> removed2 = new HashSet<String>(baseDiff.getRemoved());
    Set<String> missing2 = new HashSet<String>(baseDiff.getMissing());
    Set<String> modified2 = new HashSet<String>(baseDiff.getModified());
    Set<String> untracked2 = new HashSet<String>(baseDiff.getUntracked());
    Set<String> conflicts2 = new HashSet<String>(baseDiff.getConflicting());

    mergeList(added2, changedFiles, diffForChangedFiles.getAdded());
    mergeList(changed2, changedFiles, diffForChangedFiles.getChanged());
    mergeList(removed2, changedFiles, diffForChangedFiles.getRemoved());
    mergeList(missing2, changedFiles, diffForChangedFiles.getMissing());
    mergeList(modified2, changedFiles, diffForChangedFiles.getModified());
    mergeList(untracked2, changedFiles, diffForChangedFiles.getUntracked());
    Set<String> untrackedFolders2 = mergeUntrackedFolders(baseDiff.getUntrackedFolders(), changedFiles,
            getUntrackedFolders(diffForChangedFiles));
    mergeList(conflicts2, changedFiles, diffForChangedFiles.getConflicting());
    Set<String> ignored2 = mergeIgnored(baseDiff.getIgnoredNotInIndex(), changedFiles,
            diffForChangedFiles.getIgnoredNotInIndex());

    added = Collections.unmodifiableSet(added2);
    changed = Collections.unmodifiableSet(changed2);
    removed = Collections.unmodifiableSet(removed2);
    missing = Collections.unmodifiableSet(missing2);
    modified = Collections.unmodifiableSet(modified2);
    untracked = Collections.unmodifiableSet(untracked2);
    untrackedFolders = Collections.unmodifiableSet(untrackedFolders2);
    conflicts = Collections.unmodifiableSet(conflicts2);
    ignored = Collections.unmodifiableSet(ignored2);
}

From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java

License:Open Source License

private void buildIndexHeadDiffList() throws IOException, CoreException {
    HashMap<Repository, HashSet<IProject>> repositories = new HashMap<Repository, HashSet<IProject>>();

    for (IProject project : getProjectsInRepositoryOfSelectedResources()) {
        RepositoryMapping repositoryMapping = RepositoryMapping.getMapping(project);
        assert repositoryMapping != null;

        Repository repository = repositoryMapping.getRepository();

        HashSet<IProject> projects = repositories.get(repository);

        if (projects == null) {
            projects = new HashSet<IProject>();
            repositories.put(repository, projects);
        }//from   ww w.j a  v a 2s. c  o  m

        projects.add(project);
    }

    for (Map.Entry<Repository, HashSet<IProject>> entry : repositories.entrySet()) {
        Repository repository = entry.getKey();
        HashSet<IProject> projects = entry.getValue();

        Tree head = repository.mapTree(Constants.HEAD);
        GitIndex index = repository.getIndex();
        IndexDiff indexDiff = new IndexDiff(head, index);
        indexDiff.diff();

        for (IProject project : projects) {
            includeList(project, indexDiff.getAdded(), indexChanges);
            includeList(project, indexDiff.getChanged(), indexChanges);
            includeList(project, indexDiff.getRemoved(), indexChanges);
            includeList(project, indexDiff.getMissing(), notIndexed);
            includeList(project, indexDiff.getModified(), notIndexed);
            addUntrackedFiles(repository, project);
        }
    }
}