Example usage for org.eclipse.jgit.dircache DirCache findEntry

List of usage examples for org.eclipse.jgit.dircache DirCache findEntry

Introduction

In this page you can find the example usage for org.eclipse.jgit.dircache DirCache findEntry.

Prototype

public int findEntry(String path) 

Source Link

Document

Locate the position a path's entry is at in the index.

Usage

From source file:org.debian.dependency.sources.TestJGitSource.java

License:Apache License

/**
 * If we've initialized a work branch (removed bad files), and they are there again on second init, we assume the user knows
 * what they are doing./*w w w .  j a v  a  2s  .  c o m*/
 */
@Test
public void testBadFilesAfterInit() throws Exception {
    File clazz1 = File.createTempFile("SomeClass", ".class", directory);
    File jar1 = File.createTempFile("some-jar", ".jar", directory);

    File subdir = new File(directory, "subdir");
    subdir.mkdirs();
    File clazz2 = File.createTempFile("AnotherClass", ".class", subdir);
    File jar2 = File.createTempFile("another-jar", ".jar", subdir);

    git.add().addFilepattern(".").call();
    git.commit().setMessage("Add bad files for test").call();

    git.checkout().setCreateBranch(true).setName(WORK_BRANCH).call();

    // perform test
    source.initialize(directory, ORIGIN);

    DirCache dirCache = git.getRepository().readDirCache();
    assertTrue("Class file put there after setup is vaild",
            dirCache.findEntry(Repository.stripWorkDir(directory, clazz1)) >= 0);
    assertTrue("Class file put there after setup is vaild",
            dirCache.findEntry(Repository.stripWorkDir(directory, clazz2)) >= 0);
    assertTrue("Jar file put there after setup is vaild",
            dirCache.findEntry(Repository.stripWorkDir(directory, jar1)) >= 0);
    assertTrue("Jar file put there after setup is vaild",
            dirCache.findEntry(Repository.stripWorkDir(directory, jar2)) >= 0);
}

From source file:org.eclipse.egit.core.GitMoveDeleteHook.java

License:Open Source License

public boolean deleteFile(final IResourceTree tree, final IFile file, final int updateFlags,
        final IProgressMonitor monitor) {
    final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
    if (!force && !tree.isSynchronized(file, IResource.DEPTH_ZERO))
        return false;

    final RepositoryMapping map = RepositoryMapping.getMapping(file);
    if (map == null)
        return false;

    try {/*w  w w  . ja va 2  s.c  o m*/
        final DirCache dirc = map.getRepository().lockDirCache();
        final int first = dirc.findEntry(map.getRepoRelativePath(file));
        if (first < 0) {
            dirc.unlock();
            return false;
        }

        final DirCacheBuilder edit = dirc.builder();
        if (first > 0)
            edit.keep(0, first);
        final int next = dirc.nextEntry(first);
        if (next < dirc.getEntryCount())
            edit.keep(next, dirc.getEntryCount() - next);
        if (!edit.commit())
            tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0,
                    CoreText.MoveDeleteHook_operationError, null));
        tree.standardDeleteFile(file, updateFlags, monitor);
    } catch (IOException e) {
        tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0,
                CoreText.MoveDeleteHook_operationError, e));
    }
    return true;
}

From source file:org.eclipse.egit.core.test.op.TrackUntrackOperationTest.java

License:Open Source License

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;
        assertTrue("Wrong tracking state", tracked == expectedState);
    }//  w w w .  j  a  v  a 2  s .  c  om
}