Example usage for org.eclipse.jgit.api Git init

List of usage examples for org.eclipse.jgit.api Git init

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git init.

Prototype

public static InitCommand init() 

Source Link

Document

Return a command object to execute a init command

Usage

From source file:deployer.publishers.openshift.RhcApplicationGitRepoModificationsTest.java

License:Apache License

@Test
public void shouldUpdateGitRepoWithModifications()
        throws IOException, GitAPIException, ArchiveException, DeploymentException {
    File remoteTestDir = Files.resolve(GIT_TEST_DIR, "shouldUpdateGitRepoWithModificationsOrigin.git");
    File testDir = Files.resolve(GIT_TEST_DIR, "shouldUpdateGitRepoWithModifications");
    Files.createDirectories(testDir);

    Git remoteGit = Git.init().setBare(true).setDirectory(remoteTestDir).call();

    Git git = Git.cloneRepository().setURI(remoteTestDir.toString()).setDirectory(testDir).call();
    populateWithInitialFiles(git, testDir);

    IApplication instance = createMock(IApplication.class);
    IDomain domain = createMock(IDomain.class);
    IUser mockUser = createMock(IUser.class);

    expect(instance.getName()).andReturn("UnitTestApplication").anyTimes();
    expect(domain.getUser()).andReturn(mockUser).anyTimes();
    expect(mockUser.getRhlogin()).andReturn("UnitTestuser").anyTimes();

    replay(instance, domain, mockUser);//ww  w  .  j  a  va 2 s .c  o  m

    RhcApplication app = new RhcApplication(git, instance, domain, testDir, null);
    ByteBuffer sampleTarBall = TestUtils.createSampleAppTarBall(ArtifactType.Thrift);
    app.updateWithTarBall(sampleTarBall.array(), "v1.0");
    app.addStreamAsFile(Files.get(TestUtils.CONFIG_DIRECTORY, "extraInfo.conf"),
            new ByteArrayInputStream("Extra information".getBytes()));
    app.publishChanges();
    verify(instance, domain, mockUser);
    assertGitRepositoryFilesForUpdateGitRepoTest(testDir);
    File ensuredDir = Files.resolve(GIT_TEST_DIR, "shouldUpdateGitRepoWithModificationsEnsured");
    Git.cloneRepository().setURI(remoteTestDir.toURI().toString()).setDirectory(ensuredDir).call();
    assertGitRepositoryFilesForUpdateGitRepoTest(ensuredDir);
}

From source file:deployer.TestUtils.java

License:Apache License

public static AppDirs[] makeNumberGits(int number, String baseName) throws GitAPIException {
    List<AppDirs> gits = Lists.newArrayListWithCapacity(number);
    for (int i = 0; i < number; i++) {
        File remoteTestDir = Files.resolve(GIT_TEST_DIR, baseName + "xx" + i + ".git");
        File testDir = Files.resolve(GIT_TEST_DIR, baseName + "xx" + i);
        Files.createDirectories(testDir);
        Git remoteGit = Git.init().setBare(true).setDirectory(remoteTestDir).call();

        Git git = Git.cloneRepository().setURI(remoteTestDir.toURI().toString()).setDirectory(testDir).call();
        gits.add(new AppDirs(remoteGit, git, testDir));
    }//from   w  ww  .  j ava  2  s. c  om
    return gits.toArray(new AppDirs[gits.size()]);
}

From source file:edu.nju.cs.inform.jgit.CreateNewRepository.java

License:Apache License

public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException {
    // prepare a new folder
    File localPath = File.createTempFile("TestGitRepository", "");
    localPath.delete();/*w  w  w  . jav a2 s  .  c  o m*/

    // create the directory
    try (Git git = Git.init().setDirectory(localPath).call()) {
        System.out.println("Having repository: " + git.getRepository().getDirectory());
    }

    FileUtils.deleteDirectory(localPath);
}

From source file:edu.nju.cs.inform.jgit.porcelain.InitRepository.java

License:Apache License

public static void main(String[] args) throws IOException, GitAPIException {
    // run the init-call
    File dir = File.createTempFile("gitinit", ".test");
    if (!dir.delete()) {
        throw new IOException("Could not delete file " + dir);
    }//from ww  w.  j  a v a 2s  . c  o m

    // The Git-object has a static method to initialize a new repository
    try (Git git = Git.init().setDirectory(dir).call()) {
        System.out.println("Created a new repository at " + git.getRepository().getDirectory());
    }

    dir = File.createTempFile("repoinit", ".test");
    if (!dir.delete()) {
        throw new IOException("Could not delete file " + dir);
    }

    // you can also create a Repository-object directly from the
    try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) {
        System.out.println("Created a new repository at " + repository.getDirectory());
    }
}

From source file:edu.nju.cs.inform.jgit.unfinished.TestSubmodules.java

License:Apache License

private static File createRepository() throws IOException, GitAPIException {
    File dir = File.createTempFile("gitinit", ".test");
    dir.delete();/*w w w.  j  a v  a 2 s .  co  m*/

    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:edu.wustl.lookingglass.community.CommunityRepository.java

License:Open Source License

private Git init() throws URISyntaxException, IOException, IllegalStateException, GitAPIException {
    assert !hasGitRepository(this.repoDir);

    Git git = Git.init().setDirectory(this.repoDir).call();

    StoredConfig config = git.getRepository().getConfig();
    config.setString("core", null, "ignorecase", "false"); // Be case sensitive explicitly to work on Mac
    config.setString("core", null, "filemode", "false"); // Ignore permission changes
    config.setString("core", null, "precomposeunicode", "true"); // Use the same Unicode form on all filesystems
    config.setString("push", null, "default", "simple");
    config.save();//ww  w  .  j  ava2 s  . co m

    return git;
}

From source file:eu.atos.paas.git.Repository.java

License:Open Source License

public static Repository init(File path) throws GitAPIException, IOException {

    InitCommand cmd = Git.init();
    logger.debug("Start git init in {}", path.getPath());
    Git gitRepo = cmd.setDirectory(path).call();
    gitRepo.close();//from   w w w .j  a  v a2  s .  c o  m
    logger.debug("End git init in {}", path.getPath());
    return new Repository(path);
}

From source file:eu.hohenegger.gitmine.jgit.TestBasic.java

License:Open Source License

@Before
public void init() throws IOException, GitAPIException {
    File localPath = File.createTempFile(TMP_REPO_PREFIX, NO_EXTENSION);
    localPath.delete();//from   w w  w.j  ava  2 s. co m

    git = Git.init().setDirectory(localPath).setBare(false).call();

    commit(new PersonIdent("alice", "alice@acme.com"));
    commit(new PersonIdent("bo", "bob@acme.com"));

    miner = new MiningService();
}

From source file:eu.mihosoft.vrl.io.VersionedFile.java

License:Open Source License

/**
 * Initializes git repository.//  w ww  . j  a  va 2s  .  c om
 *
 * <p><b>Warning:</b> Be careful when calling this method. It will destroy
 * any existing repository!</p>
 *
 * @throws IOException
 */
private void initGit() throws IOException {

    File repoFile = new File(tmpFolder.getAbsolutePath() + "/.git");

    // delete existing repository
    if (repoFile.exists()) {
        IOUtil.deleteDirectory(repoFile);
    }

    Git git = null;

    try {
        // initialize git repository
        Git.init().setDirectory(tmpFolder).call();
        git = Git.open(tmpFolder);
        git.add().addFilepattern(".").call();
        // perform initial commit
        git.commit().setMessage("initial commit").setAuthor("VRL-User", "").call();

        git.getRepository().close();

    } catch (NoHeadException ex) {
        throw new IOException("Git exception", ex);
    } catch (NoMessageException ex) {
        throw new IOException("Git exception", ex);
    } catch (UnmergedPathException ex) {
        throw new IOException("Git exception", ex);
    } catch (ConcurrentRefUpdateException ex) {
        throw new IOException("Git exception", ex);
    } catch (JGitInternalException ex) {
        throw new IOException("Git exception", ex);
    } catch (WrongRepositoryStateException ex) {
        throw new IOException("Git exception", ex);
    } catch (NoFilepatternException ex) {
        throw new IOException("Git exception", ex);
    } catch (IOException ex) {
        throw new IOException("Git exception", ex);
    } finally {
        if (git != null) {
            git.getRepository().close();
        }
    }
}

From source file:fr.duminy.tools.jgit.JGitToolboxTest.java

License:Open Source License

private Git createGitRepository(String name) throws IOException, GitAPIException {
    File dir = folder.newFolder(name);

    Git git = Git.init().setDirectory(dir).call();
    addAndCommitFile(git);/*from w w w  . j a va2  s  .  c  o  m*/
    return git;
}