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

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

Introduction

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

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:de.blizzy.documentr.repository.ProjectRepositoryManagerTest.java

License:Open Source License

@Test
public void createCentralRepository() throws IOException, GitAPIException {
    File reposDir = tempDir.getRoot();
    ProjectRepositoryManager repoManager = new ProjectRepositoryManager("project", reposDir, lockManager, //$NON-NLS-1$
            eventBus);//from w ww. j  av  a 2  s. c o m
    ILockedRepository lockedRepo = null;
    try {
        lockedRepo = repoManager.createCentralRepository(USER);
    } finally {
        Closeables.closeQuietly(lockedRepo);
        lockedRepo = null;
    }

    Repository repo = null;
    try {
        repo = new RepositoryBuilder().findGitDir(new File(reposDir, "_central")).build(); //$NON-NLS-1$
        assertEquals(new File(new File(reposDir, "_central"), ".git"), repo.getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$
        assertNotNull(CommitUtils.getCommit(repo, Constants.MASTER));
    } finally {
        RepositoryUtil.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.repository.RepositoryUtil.java

License:Open Source License

public static File getWorkingDir(Repository repo) {
    return repo.getDirectory().getParentFile();
}

From source file:eu.hohenegger.gitmine.ui.views.StatisticsView.java

License:Open Source License

@Inject
@Optional//from  ww w. j a va2 s.c  o  m
private void openRepository(@UIEventTopic(VIEWCOM_STATISTICS_OPEN) Repository repository, UISynchronize sync) {

    try {
        part.setLabel(repository.getDirectory() + " - " + repository.getBranch());
        // If you want to update the UI, run it in the UI thread
        sync.syncExec(new Runnable() {
            @Override
            public void run() {
                reset();
            }
        });

        graph.addCurve("Commits", miningservice.scanCommitsPerDay(repository), new RGB(0, 0, 255), "#", true);
    } catch (IOException e) {
        // TODO log
        MessageDialog.openError(activeShell, "Error", e.getLocalizedMessage());
    }
}

From source file:eu.hohenegger.gitmine.ui.views.TimeLapseView.java

License:Open Source License

private String createRelativePath(String absolutePath, Repository repository) {
    String relativePath;//www. j a v a2 s . co  m
    File directory = repository.getDirectory();
    String base = "";
    try {
        base = directory.getParentFile().getCanonicalPath();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    relativePath = createRelativePath(base, absolutePath);
    return relativePath;
}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

@Test
public void testReadRepo() throws IOException, GitAPIException {
    File repoFile = createSampleGitRepo();

    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repo = builder.setGitDir(repoFile).readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();/*from   www . j a v a 2  s .  c  o m*/

    LOG.log(Level.INFO, "directory: {0}", repo.getDirectory().getAbsolutePath());

    LOG.log(Level.INFO, "Having repository: {0}", repo.getDirectory().getAbsolutePath());

    LOG.log(Level.INFO, "current branch: {0}", repo.getBranch());
}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

private static File createFile(Repository repository, String filePath) {

    try {/*from ww  w.ja  v a 2  s.  c o  m*/
        // create the file

        File targetFile = new File(repository.getDirectory().getParent(), filePath);
        File parent = targetFile.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalStateException("Couldn't create dir: " + parent);
        }

        targetFile.createNewFile();

        PrintWriter pw = new PrintWriter(targetFile);
        pw.println("hello");
        pw.close();

        // run the add-call
        new Git(repository).add().addFilepattern(filePath).call();

        return targetFile;

    } catch (Exception ex) {
        throw new RuntimeException("Error while creating file!", ex);
    }
}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

/**
 * Creates a sample josman repo/*from w  w w  . ja  va  2  s. c om*/
 *
 *
 * @return
 * @throws IOException
 * @throws GitAPIException
 */
private static File createJosmanSampleRepo() {
    Repository repository;
    try {
        repository = CookbookHelper.createNewRepository();

        LOG.log(Level.INFO, "Temporary repository at {0}", repository.getDirectory());

        createFiles(repository, "docs/README.md", "docs/CHANGES.md", "docs/img/a.jpg", "src/main/java/a.java",
                "src/main/java/b.java", "README.md", "LICENSE.txt");

        // and then commit the changes
        new Git(repository).commit().setMessage("Added test files").call();

        File dir = repository.getDirectory();

        repository.close();

        return dir;
    } catch (Exception ex) {
        throw new RuntimeException("Error while creating new repo!", ex);
    }

}

From source file:eu.trentorise.opendata.josman.test.GitTest.java

private static File createSampleGitRepo() throws IOException, GitAPIException {
    Repository repository = CookbookHelper.createNewRepository();

    System.out.println("Temporary repository at " + repository.getDirectory());

    // create the file
    File myfile = new File(repository.getDirectory().getParent(), "testfile");
    myfile.createNewFile();/*  w  ww . j a  va  2  s  .c  om*/

    // run the add-call
    new Git(repository).add().addFilepattern("testfile").call();

    // and then commit the changes
    new Git(repository).commit().setMessage("Added testfile").call();

    LOG.info("Added file " + myfile + " to repository at " + repository.getDirectory());

    File dir = repository.getDirectory();

    repository.close();

    return dir;

}

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

License:Open Source License

/**
 * Indicates if we should analyze the Git repository of the given project.
 * /*from w  w w. ja  v  a 2s  .c o  m*/
 * @param project
 *            The project to analyze
 * @param provider
 *            The Git repository provider
 * @return <code>true</code> if we should explore the repository linked to the given project, false
 *         otherwise.
 */
private boolean shouldExplore(IProject project, GitProvider provider) {
    String repositoryPath = null;

    GitProjectData gitProjectData = provider.getData();
    RepositoryMapping repositoryMapping = gitProjectData.getRepositoryMapping(project);
    if (repositoryMapping != null) {
        Repository repository = repositoryMapping.getRepository();
        if (repository != null) {
            repositoryPath = repository.getDirectory().getAbsolutePath();
        }
    }

    return repositoryPath != null && !this.repositoryPreviouslyExplored.contains(repositoryPath);
}

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

License:Open Source License

/**
 * Launches the exploration of the JGit/EGit data from the given project and its Git repository provider.
 * //from  w w w .ja  va2s.c  o  m
 * @param project
 *            The project to explore
 * @param provider
 *            The Git repository provider of the project
 * @param monitor
 *            The progress monitor
 * @return The Ariadne repository representing the Git repository used on the given project,
 *         <code>null</code> otherwise.
 */
public fr.obeo.ariadne.model.scm.Repository doExplore(IProject project, GitProvider provider,
        IProgressMonitor monitor) {
    GitProjectData gitProjectData = provider.getData();
    RepositoryMapping repositoryMapping = gitProjectData.getRepositoryMapping(project);
    if (repositoryMapping != null) {
        Repository repository = repositoryMapping.getRepository();
        if (repository != null) {
            // Create or recreate the Ariadne SCM repository matching this Git repository
            fr.obeo.ariadne.model.scm.Repository ariadneRepository = this.getOrCreateRepository(repository,
                    monitor);

            this.computeCommits(repository, ariadneRepository, monitor);
            this.computeParents(repository, ariadneRepository, monitor);
            this.computeReferences(repository, ariadneRepository, monitor);

            // Add the repository as explored
            this.repositoryPreviouslyExplored.add(repository.getDirectory().getAbsolutePath());

            return ariadneRepository;
        }
    }
    return null;
}