Example usage for org.eclipse.jgit.storage.file FileRepositoryBuilder create

List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder create

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.file FileRepositoryBuilder create.

Prototype

public static Repository create(File gitDir) throws IOException 

Source Link

Document

Convenience factory method to construct a org.eclipse.jgit.internal.storage.file.FileRepository .

Usage

From source file:org.archicontribs.modelrepository.GitHelper.java

License:Open Source License

public static Repository createNewRepository(File localPath) throws IOException {
    Repository repository = FileRepositoryBuilder.create(new File(localPath, ".git"));
    repository.create();//  w w w  . ja  v  a  2 s. c  o  m
    return repository;
}

From source file:org.craftercms.studio.impl.v1.deployment.EnvironmentStoreGitBranchDeployer.java

License:Open Source License

private boolean createEnvironmentStoreRepository(String site) {
    boolean success = true;
    Path siteEnvironmentStoreRepoPath = Paths.get(environmentsStoreRootPath, site, environment);
    try {// w ww  .j a  v a2 s . c o m
        Files.deleteIfExists(siteEnvironmentStoreRepoPath);
        siteEnvironmentStoreRepoPath = Paths.get(environmentsStoreRootPath, site, environment, ".git");
        Repository repository = FileRepositoryBuilder.create(siteEnvironmentStoreRepoPath.toFile());
        repository.create();

        Git git = new Git(repository);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setMessage("initial content").setAllowEmpty(true).call();
    } catch (IOException | GitAPIException e) {
        logger.error("Error while creating repository for site " + site, e);
        success = false;
    }
    return success;
}

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryHelper.java

License:Open Source License

public Repository createGitRepository(Path path) {
    Repository toReturn;//from   w w w  .j  a  v a  2 s  .c  o  m
    path = Paths.get(path.toAbsolutePath().toString(), GIT_ROOT);
    try {
        toReturn = FileRepositoryBuilder.create(path.toFile());
        toReturn.create();

        // Get git configuration
        StoredConfig config = toReturn.getConfig();
        // Set compression level (core.compression)
        config.setInt(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_COMPRESSION,
                CONFIG_PARAMETER_COMPRESSION_DEFAULT);
        // Set big file threshold (core.bigFileThreshold)
        config.setString(CONFIG_SECTION_CORE, null, CONFIG_PARAMETER_BIG_FILE_THRESHOLD,
                CONFIG_PARAMETER_BIG_FILE_THRESHOLD_DEFAULT);
        // Save configuration changes
        config.save();
    } catch (IOException e) {
        logger.error("Error while creating repository for site with path" + path.toString(), e);
        toReturn = null;
    }

    return toReturn;
}

From source file:org.dstadler.jgit.helper.CookbookHelper.java

License:Apache License

public static Repository createNewRepository() throws IOException {
    // prepare a new folder
    File localPath = File.createTempFile("TestGitRepository", "");
    if (!localPath.delete()) {
        throw new IOException("Could not delete temporary file " + localPath);
    }//from www. ja v a  2 s .  c om

    // create the directory
    Repository repository = FileRepositoryBuilder.create(new File(localPath, ".git"));
    repository.create();

    return repository;
}

From source file:org.dstadler.jgit.unfinished.TestSubmodules.java

License:Apache License

private static File createRepository() throws IOException, GitAPIException {
    File dir = File.createTempFile("gitinit", ".test");
    if (!dir.delete()) {
        throw new IOException("Could not delete temporary file " + dir);
    }/* w w w.  j a v  a2s.  c om*/

    Git.init().setDirectory(dir).call();

    try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) {
        System.out.println("Created a new repository at " + repository.getDirectory());
    }

    return dir;
}

From source file:org.eclipse.egit.core.internal.util.ResourceUtilTest.java

License:Open Source License

@Before
public void before() throws Exception {
    repository = FileRepositoryBuilder.create(gitDir);
    repository.create();
    connect(project.getProject());
}

From source file:org.eclipse.egit.core.storage.GitBlobStorageTest.java

License:Open Source License

@Override
@Before//  ww w .j  a va  2  s.c o m
public void setUp() throws Exception {
    super.setUp();
    repository = FileRepositoryBuilder.create(gitDir);
    repository.create();
}

From source file:org.eclipse.egit.core.storage.GitBlobStorageTest.java

License:Open Source License

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);

    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();//from  w w  w.  j a  va  2  s . c o  m

    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);

    try {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        Git git = new Git(singleProjectRepo);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true)
                .setMessage("First commit").call();

        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(
                Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}

From source file:org.eclipse.egit.ui.internal.push.PushBranchWizardTest.java

License:Open Source License

private Repository createRemoteRepository() throws IOException {
    File gitDir = new File(getTestDirectory(), "pushbranchremote");
    Repository repo = FileRepositoryBuilder.create(gitDir);
    repo.create(true);//  w  ww.ja  v  a2  s  .  c  o m
    assertTrue(repo.isBare());
    return repo;
}

From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewRemoteAwareChangeSetModelTest.java

License:Open Source License

protected void createMockLogicalRepository() throws Exception {
    File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT);
    Repository repo = FileRepositoryBuilder.create(gitDir);
    repo.create();// w  w  w  .j a va 2s.c o m

    // we need to commit into master first
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT);

    if (project.exists()) {
        project.delete(true, null);
        TestUtil.waitForJobs(100, 5000);
    }
    IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT);
    desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath()));
    project.create(desc, null);
    project.open(null);
    assertTrue("Project is not accessible: " + project, project.isAccessible());

    TestUtil.waitForJobs(50, 5000);
    try {
        new ConnectProviderOperation(project, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(project);

    mockLogicalFile = project.getFile("index.mocklogical");
    mockLogicalFile.create(
            new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false,
            null);
    IFile file1 = project.getFile("file1.txt");
    file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null);
    IFile file2 = project.getFile("file2.txt");
    file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null);

    IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 };
    List<IFile> untracked = new ArrayList<>();
    untracked.addAll(Arrays.asList(commitables));
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR,
            TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    RevCommit firstCommit = op.getCommit();

    CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable",
            firstCommit);
    createBranchOp.execute(null);

    // Delete file2.txt from logical model and add file3
    mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt");
    file2.delete(true, null);
    touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified");
    IFile file3 = project.getFile("file3.txt");
    file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null);
    commitables = new IFile[] { mockLogicalFile, file1, file2, file3 };
    untracked = new ArrayList<>();
    untracked.add(file3);
    op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER,
            "Second commit");
    op.execute(null);
}