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

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

Introduction

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

Prototype

@NonNull
public File getIndexFile() throws NoWorkTreeException 

Source Link

Document

Get the index file location or null if repository isn't local.

Usage

From source file:com.amazonaws.eclipse.elasticbeanstalk.git.AWSGitPushCommand.java

License:Open Source License

private void clearOutRepository(Repository repository) throws IOException {
    // Delete all the old files before copying the new files
    final File gitMetadataDirectory = repository.getIndexFile().getParentFile();

    FileFilter fileFilter = new FileFilter() {
        public boolean accept(final File file) {
            if (file.equals(gitMetadataDirectory))
                return false;
            if (!file.getParentFile().equals(repoLocation))
                return false;
            return true;
        }/*from ww  w  .  j a  va  2s  . c om*/
    };

    for (File f : repoLocation.listFiles(fileFilter)) {
        FileUtils.delete(f, FileUtils.RECURSIVE);
    }
}

From source file:com.bacoder.scmtools.git.internal.CloneAndProcessCommand.java

License:Apache License

@Override
protected void doCheckout(final Repository repository, RevCommit commit)
        throws MissingObjectException, IncorrectObjectTypeException, IOException, GitAPIException {
    DirCache dirCache;/*w  w w  . j  a va 2s  .com*/
    if (isInMemory()) {
        dirCache = new InMemoryDirCache(repository.getIndexFile(), repository.getFS());
        dirCache.setRepository(repository);
    } else {
        dirCache = repository.lockDirCache();
    }
    CloneAndProcessDirCacheCheckout checkout = new CloneAndProcessDirCacheCheckout(repository, dirCache,
            commit.getTree(), pathPrefix);
    checkout.setProcessor(processor);
    checkout.checkout();

    submodulesConfig = checkout.getSubmodulesConfig();
    if (cloneSubmodules) {
        cloneSubmodules(repository);
    }
}

From source file:com.google.gerrit.server.git.ReadOnlyRepository.java

License:Apache License

private static BaseRepositoryBuilder<?, ?> builder(Repository r) {
    checkNotNull(r);//from   w ww . j av  a2  s.  c o m
    BaseRepositoryBuilder<?, ?> builder = new BaseRepositoryBuilder<>().setFS(r.getFS())
            .setGitDir(r.getDirectory());

    if (!r.isBare()) {
        builder.setWorkTree(r.getWorkTree()).setIndexFile(r.getIndexFile());
    }
    return builder;
}

From source file:com.googlesource.gerrit.plugins.gitiles.FilteredRepository.java

License:Apache License

private static RepositoryBuilder toBuilder(Repository repo) {
    RepositoryBuilder b = new RepositoryBuilder().setGitDir(repo.getDirectory()).setFS(repo.getFS());
    if (!repo.isBare()) {
        b.setWorkTree(repo.getWorkTree()).setIndexFile(repo.getIndexFile());
    }/*from  w w w .ja  va  2  s.  c o m*/
    return b;
}

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

License:Open Source License

@Test
public void testDeleteProject() throws Exception {
    TestProject project = initRepoAboveProjectInsideWs("P/", "");
    testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
    AddToIndexOperation addToIndexOperation = new AddToIndexOperation(
            new IResource[] { project.getProject().getFile("file.txt") });
    addToIndexOperation.execute(null);/*from   w  w w .j  av a  2 s . co  m*/

    RepositoryMapping mapping = RepositoryMapping.getMapping(project.getProject());
    IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
    Repository db = new FileRepository(gitDirAbsolutePath.toFile());
    DirCache index = DirCache.read(db.getIndexFile(), db.getFS());
    assertNotNull(index.getEntry("P/Project-1/file.txt"));
    db.close();
    db = null;
    project.getProject().delete(true, null);
    assertNull(RepositoryMapping.getMapping(project.getProject()));
    // Check that the repo is still there. Being a bit paranoid we look for
    // a file
    assertTrue(gitDirAbsolutePath.toString(), gitDirAbsolutePath.append("HEAD").toFile().exists());

    db = new FileRepository(gitDirAbsolutePath.toFile());
    index = DirCache.read(db.getIndexFile(), db.getFS());
    // FIXME: Shouldn't we unstage deleted projects?
    assertNotNull(index.getEntry("P/Project-1/file.txt"));
    db.close();
}