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:com.rimerosolutions.ant.git.tasks.InitTask.java

License:Apache License

@Override
public void execute() {
    try {/*  ww w  .j  a va 2  s .com*/
        Git git = Git.init().setBare(bare).setDirectory(getDirectory()).call();

        git.getRepository().close();
    } catch (GitAPIException e) {
        throw new GitBuildException(MESSAGE_INIT_FAILED, e);
    }
}

From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java

License:Apache License

private void initGitAndClone() throws GitAPIException {
    Git.init().setDirectory(cut.gitDirectory).setBare(true).call().close();
    Git.cloneRepository().setURI(cut.gitDirectory.getAbsolutePath()).setDirectory(gitCloneDirectory).call()
            .close();/*from  ww  w  . ja v  a  2 s .co m*/
}

From source file:com.stormcloud.ide.api.git.GitManager.java

License:Open Source License

public void initRepository() {

    InitCommand initCommand = Git.init();

}

From source file:com.tasktop.c2c.server.internal.profile.service.template.GitServiceCloner.java

License:Open Source License

private void copyRepo(ScmRepository scmRepo, CloneContext context)
        throws IOException, JGitInternalException, GitAPIException {

    File workDirectory = null;/*from   w ww.  ja va 2  s.  co m*/
    try {
        Project templateProject = context.getTemplateService().getProjectServiceProfile().getProject();
        String cloneUrl = jgitProvider.computeRepositoryUrl(templateProject.getIdentifier(), scmRepo.getName());

        AuthUtils.assumeSystemIdentity(templateProject.getIdentifier());
        tenancyManager.establishTenancyContext(context.getTemplateService());

        workDirectory = createTempDirectory();
        Git git = Git.cloneRepository().setDirectory(workDirectory)
                .setBranch(Constants.R_HEADS + Constants.MASTER).setURI(cloneUrl).call();

        AuthUtils.assumeSystemIdentity(
                context.getTargetService().getProjectServiceProfile().getProject().getIdentifier());
        tenancyManager.establishTenancyContext(context.getTargetService());

        FileUtils.deleteDirectory(git.getRepository().getDirectory());

        git = Git.init().setDirectory(git.getRepository().getDirectory().getParentFile()).call();

        maybeRewriteRepo(workDirectory, context);

        String pushUrl = jgitProvider.computeRepositoryUrl(
                context.getTargetService().getProjectServiceProfile().getProject().getIdentifier(),
                scmRepo.getName());

        // FIXME: User's locale is not defined here
        String commitMessage = messageSource.getMessage("project.template.git.commitMessage",
                new Object[] { templateProject.getName() }, null);

        git.add().addFilepattern(".").call();
        git.commit().setCommitter(committerName, committerEmail).setMessage(commitMessage).call();
        git.getRepository().getConfig().setString("remote", "target", "url", pushUrl);
        git.push().setRemote("target").setPushAll().call();
    } finally {
        if (workDirectory != null) {
            FileUtils.deleteDirectory(workDirectory);
        }
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java

License:Open Source License

@Secured({ Role.Admin })
@Override/*from  w  ww.  j  av  a 2  s .c o  m*/
public void addExternalRepository(String url) {
    try {
        String repoName = getRepoDirNameFromExternalUrl(url);
        File dir = new File(repositoryProvider.getTenantMirroredBaseDir(), repoName);
        Git git = Git.init().setBare(true).setDirectory(dir).call();
        RemoteConfig config = new RemoteConfig(git.getRepository().getConfig(), Constants.DEFAULT_REMOTE_NAME);
        config.addURI(new URIish(url));
        config.update(git.getRepository().getConfig());
        git.getRepository().getConfig().save();
    } catch (JGitInternalException e) {
        throw new RuntimeException(e);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    }

}

From source file:de.blizzy.documentr.page.PageUtilTest.java

License:Open Source License

@Test
public void toPageVersion() throws GitAPIException, IOException {
    File repoDir = tempDir.getRoot();
    Git git = Git.init().setDirectory(repoDir).call();
    PersonIdent ident = new PersonIdent("user", "user@example.com"); //$NON-NLS-1$ //$NON-NLS-2$
    git.commit().setAuthor(ident).setCommitter(ident).setMessage("test").call(); //$NON-NLS-1$
    RevCommit commit = CommitUtils.getHead(git.getRepository());

    PageVersion pageVersion = PageUtil.toPageVersion(commit);
    assertEquals("user", pageVersion.getLastEditedBy()); //$NON-NLS-1$
    assertSecondsAgo(pageVersion.getLastEdited(), 5);
    assertEquals(commit.getName(), pageVersion.getCommitName());
}

From source file:de.ks.blogging.grav.ui.post.BlogIntegrationAdvancedFixture.java

License:Apache License

public void createBlogFolders() throws Exception {
    cleanup();//w  ww.j av a2  s  .c  o  m
    dateTime = LocalDateTime.now().withSecond(0).withNano(0);
    String tmpDir = StandardSystemProperty.JAVA_IO_TMPDIR.value();
    blogFolder = new File(tmpDir, "blog");
    blogFolder.mkdir();

    git = Git.init().setDirectory(blogFolder).call();
    Path dir = Paths.get(blogFolder.getAbsolutePath(), "user", "pages", "01.blog");
    Files.createDirectories(dir);
    this.pagesDir = dir.toFile();

    withGit("entry1", () -> {
        makeBlogEntry("entry1", "post 1", "Hello Sauerland");
    });
    withGit("entry2", () -> {
        makeBlogEntry("entry2", "post 2", "Hello World");
    });
    withGit("modify entry2", () -> {
        modifyBlogEntry("entry2", "post 2", "Hello PCT");
    });
    withGit("entry3", () -> {
        makeBlogEntry("entry3", "post 3", "Hungry!");
    });
    withGit("delete entry 1", () -> {
        FileUtil.deleteDir(new File(pagesDir, "entry1"));
    });

    git.close();
}

From source file:de.ks.blogging.grav.ui.post.BlogIntegrationBasicFixture.java

License:Apache License

public void createBlogFolders(boolean withGit) throws Exception {
    dateTime = LocalDateTime.now().withSecond(0).withNano(0);
    String tmpDir = StandardSystemProperty.JAVA_IO_TMPDIR.value();
    fileBlog1 = new File(tmpDir, "blog1");
    fileBlog2 = new File(tmpDir, "blog2");
    fileBlog1.mkdir();//from w w  w . j ava 2 s  .co  m
    fileBlog2.mkdir();

    Git git = null;
    if (withGit) {
        git = Git.init().setDirectory(fileBlog2).call();
    }

    Files.write(new File(fileBlog1, "blog1.md").toPath(), Arrays.asList(getBlog("post 1", "Hello Sauerland")));
    Files.write(new File(fileBlog2, "blog2_a.md").toPath(), Arrays.asList(getBlog("post 1", "Hello Woll")));
    if (git != null) {
        git.add().addFilepattern("blog2_a.md").call();
        RevCommit commit = git.commit().setAll(true).setMessage("commit 1").call();
        commit1 = commit.getId().getName();
    }
    Files.write(new File(fileBlog2, "blog2_b.md").toPath(), Arrays.asList(getBlog("post 2", "Ein Bier bitte")));
    if (git != null) {
        git.add().addFilepattern("blog2_b.md").call();
        RevCommit commit = git.commit().setAll(true).setMessage("commit 2").call();
        commit2 = commit.getId().getName();
    }
    if (git != null) {
        Files.write(new File(fileBlog2, "blog2_c.md").toPath(),
                Arrays.asList(getBlog("post 3", "Ein Tischgedeck bitte")));

        git.add().addFilepattern("blog2_c.md").call();
        RevCommit commit = git.commit().setAll(true).setMessage("commit 3").call();
        commit3 = commit.getId().getName();

        Files.move(new File(fileBlog2, "blog2_c.md").toPath(), new File(fileBlog2, "blog2_d.md").toPath());

        git.add().addFilepattern("blog2_c.md").addFilepattern("blog2_d.md").call();
        commit = git.commit().setAll(true).setMessage("commit moved").call();
        commitMoved = commit.getId().getName();

        Files.delete(new File(fileBlog2, "blog2_d.md").toPath());

        git.add().addFilepattern("blog2_d.md").call();
        commit = git.commit().setAll(true).setMessage("commit deleted").call();
        commitDeleted = commit.getId().getName();
    }
}

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

License:Apache License

private void testSingleInstance(int existing) throws DeploymentException, GitAPIException, IOException {
    String strExisting = Integer.toString(existing);
    File remoteTestDir = Files.resolve(GIT_TEST_DIR, strExisting, "thriftRunnerviaOpenshift.git");
    File testDir = Files.resolve(GIT_TEST_DIR, strExisting, "thriftRunnerviaOpenshift");
    System.out.println(testDir);/*w ww .  ja  v a  2 s.c  o  m*/
    Files.createDirectories(testDir);

    AppDirs[] theGits = makeNumberGits(existing, existing + "/thriftRunnerviaOpenshift");

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

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

    Rhc rhc = createMock(Rhc.class);

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

    expect(instance.getName()).andReturn("UnitTestApplication").anyTimes();
    expect(domain.getUser()).andReturn(mockUser).anyTimes();
    expect(mockUser.getRhlogin()).andReturn("UnitTestuser").anyTimes();
    if (existing == 0 || existing == 1) {
        expect(rhc.listApplicationInstances(TestUtils.getOpenShiftAppName(),
                TestUtils.getOpenShiftDomainName())).andReturn(Collections.EMPTY_LIST).once();
    } else {
        expect(rhc.listApplicationInstances(TestUtils.getOpenShiftAppName(),
                TestUtils.getOpenShiftDomainName())).andReturn(getExistingInstances(theGits, instance, domain))
                        .once();
        instance.stop();
        expectLastCall().times(existing - 1);
        instance.destroy();
        expectLastCall().times(existing - 1);
    }

    expect(rhc.getOrCreateApplication(TestUtils.buildOpenShiftAppName(0), TestUtils.getOpenShiftDomainName(),
            new StandaloneCartridge("java-thriftrunner"), ApplicationScale.NO_SCALE, GearProfile.SMALL))
                    .andReturn(new RhcApplication(git, instance, domain, testDir, null)).once();

    expect(instance.getEnvironmentVariables()).andReturn(new HashMap<String, IEnvironmentVariable>())
            .anyTimes();
    expect(instance.addEnvironmentVariable("EZBAKE_APPLICATION_NAME", TestUtils.APP_NAME))
            .andReturn(envVariableValue("EZBAKE_APPLICATION_NAME", TestUtils.APP_NAME)).anyTimes();
    expect(instance.addEnvironmentVariable("EZBAKE_SERVICE_NAME", TestUtils.SERVICE_NAME))
            .andReturn(envVariableValue("EZBAKE_SERVICE_NAME", TestUtils.SERVICE_NAME)).anyTimes();
    expect(instance.getEmbeddedCartridges()).andReturn(new ArrayList<IEmbeddedCartridge>()).anyTimes();

    IEmbeddedCartridge cart = createMock(IEmbeddedCartridge.class);
    expect(instance.addEmbeddableCartridge(new EmbeddableCartridge("logstash"))).andReturn(cart).anyTimes();
    expect(instance.addEmbeddableCartridge(new EmbeddableCartridge("cron"))).andReturn(cart).anyTimes();

    replay(instance, domain, mockUser, ezReverseProxyRegister, rhc);

    EzOpenShiftPublisher publisher = new EzOpenShiftPublisherMock(rhc, ezReverseProxyRegister);
    DeploymentArtifact deploymentArtifact = createSampleDeploymentArtifact(ArtifactType.Thrift);
    publisher.publish(deploymentArtifact, ThriftTestUtils.generateTestSecurityToken("U"));
    verify(instance, domain, mockUser, ezReverseProxyRegister, rhc);
    assertGitRepositoryFilesForUpdateGitRepoTest(testDir);
}

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

License:Apache License

private File runSingleInstanceTest(int existing, DeploymentArtifact deploymentArtifact) throws Exception {
    String strExisting = Integer.toString(existing);
    File remoteTestDir = Files.resolve(TestUtils.GIT_TEST_DIR, strExisting, "webappviaOpenshift.git");
    File testDir = Files.resolve(TestUtils.GIT_TEST_DIR, strExisting, "webappviaOpenshift");
    System.out.println(testDir);/*ww w  . ja  v a  2s  .co  m*/
    Files.createDirectories(testDir);

    ArtifactHelpers.addFilesToArtifact(deploymentArtifact,
            new JavaWebAppArtifactContentsPublisher().generateEntries(deploymentArtifact));

    TestUtils.AppDirs[] theGits = TestUtils.makeNumberGits(existing, existing + "/webappviaOpenshift");

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

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

    Rhc rhc = createMock(Rhc.class);

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

    ThriftClientPool clientPool = createMockPool((existing >= 2 ? existing : 1), "EzBakeFrontend",
            EzReverseProxyConstants.SERVICE_NAME, ezReverseProxyClient);
    EzReverseProxyRegister ezReverseProxyRegister = new EzReverseProxyRegister(
            new EzDeployerConfiguration(new Properties()), clientPool);

    expect(instance.getName()).andReturn("UnitTestApplication").anyTimes();
    expect(instance.getApplicationUrl()).andReturn("http://unit-test.local/").anyTimes();
    expect(domain.getUser()).andReturn(mockUser).anyTimes();
    expect(mockUser.getRhlogin()).andReturn("UnitTestuser").anyTimes();
    if (existing == 0 || existing == 1) {
        expect(rhc.listApplicationInstances(TestUtils.getOpenShiftAppName(),
                TestUtils.getOpenShiftDomainName())).andReturn(Collections.EMPTY_LIST).once();
    } else {
        expect(rhc.listApplicationInstances(TestUtils.getOpenShiftAppName(),
                TestUtils.getOpenShiftDomainName()))
                        .andReturn(TestUtils.getExistingInstances(theGits, instance, domain)).once();
        instance.stop();
        expectLastCall().times(existing - 1);
        instance.destroy();
        expectLastCall().times(existing - 1);
        ezReverseProxyClient.removeUpstreamServerRegistration(
                eqRegistration("example.local/" + TestUtils.SERVICE_NAME + "/", TestUtils.SERVICE_NAME,
                        "unit-test.local:443", ""));
        expectLastCall().times(existing - 1);
    }

    ezReverseProxyClient
            .addUpstreamServerRegistration(eqRegistration("example.local/" + TestUtils.SERVICE_NAME + "/",
                    TestUtils.SERVICE_NAME, "unit-test.local:443", ""));

    expect(rhc.getOrCreateApplication(TestUtils.buildOpenShiftAppName(0), TestUtils.getOpenShiftDomainName(),
            new StandaloneCartridge("jbossas"), ApplicationScale.NO_SCALE, GearProfile.SMALL))
                    .andReturn(new RhcApplication(git, instance, domain, testDir, null)).once();

    expect(instance.getEnvironmentVariable("OPENSHIFT_GEAR_DNS"))
            .andReturn(envVariableValue("OPENSHIFT_GEAR_DNS", "unit-test.local")).anyTimes();
    expect(instance.getEnvironmentVariable("OPENSHIFT_JAVA_THRIFTRUNNER_TCP_PROXY_PORT"))
            .andReturn(envVariableValue("OPENSHIFT_JAVA_THRIFTRUNNER_TCP_PROXY_PORT", "32456")).anyTimes();
    expect(instance.getEnvironmentVariables()).andReturn(new HashMap<String, IEnvironmentVariable>())
            .anyTimes();
    expect(instance.addEnvironmentVariable("EZBAKE_APPLICATION_NAME", TestUtils.APP_NAME))
            .andReturn(envVariableValue("EZBAKE_APPLICATION_NAME", TestUtils.APP_NAME)).anyTimes();
    expect(instance.addEnvironmentVariable("EZBAKE_SERVICE_NAME", TestUtils.SERVICE_NAME))
            .andReturn(envVariableValue("EZBAKE_SERVICE_NAME", TestUtils.SERVICE_NAME)).anyTimes();
    expect(instance.getEmbeddedCartridges()).andReturn(new ArrayList<IEmbeddedCartridge>()).anyTimes();

    IEmbeddedCartridge cart = createMock(IEmbeddedCartridge.class);
    expect(instance.addEmbeddableCartridge(new EmbeddableCartridge("logstash"))).andReturn(cart).anyTimes();
    expect(instance.addEmbeddableCartridge(new EmbeddableCartridge("cron"))).andReturn(cart).anyTimes();
    replay(instance, domain, mockUser, ezReverseProxyClient, rhc);

    EzOpenShiftPublisher publisher = new EzOpenShiftPublisherMock(rhc, ezReverseProxyRegister);
    publisher.publish(deploymentArtifact, ThriftTestUtils.generateTestSecurityToken("U"));
    verify(instance, domain, mockUser, ezReverseProxyClient, rhc, clientPool);
    return testDir;
}