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

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

Introduction

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

Prototype

public static CloneCommand cloneRepository() 

Source Link

Document

Return a command object to execute a clone command

Usage

From source file:org.kie.workbench.common.services.backend.compiler.rest.client.MavenRestClientTest.java

License:Apache License

@Test
public void postTest() {
    try {/*  ww w.j a  v a2 s  .  co m*/
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();

        final String repoName = "myrepo";
        final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName),
                new HashMap<String, Object>() {
                    {
                        put("init", Boolean.TRUE);
                        put("internal", Boolean.TRUE);
                    }
                });

        ioService.startBatch(fs);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));

        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"),
                new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));

        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"),
                new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));

        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));

        ioService.endBatch();

        Path tmpRootCloned = Files.createTempDirectory("cloned");
        Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), "dummy"));

        final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");

        final Git cloned = Git.cloneRepository()
                .setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false)
                .setDirectory(gitClonedFolder).call();

        assertThat(cloned).isNotNull();
        mavenRepoPath = Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = Paths.get(gitClonedFolder + "/dummy/");

        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(deploymentUrl.toString() + "rest/maven/");
        MultivaluedMap headersMap = new MultivaluedHashMap();
        headersMap.add("project", tmpRoot.toAbsolutePath().toString() + "/dummy");
        headersMap.add("mavenrepo", mavenRepoPath.toAbsolutePath().toString());
        headersMap.add("settings_xml", mavenSettingsPath);
        Future<Response> responseFuture = target.request().headers(headersMap).async()
                .post(Entity.entity(String.class, MediaType.TEXT_PLAIN));
        Response response = responseFuture.get();
        assertThat(response.getStatusInfo().getStatusCode()).isEqualTo(200);
        InputStream is = response.readEntity(InputStream.class);
        byte[] serializedCompilationResponse = IOUtils.toByteArray(is);

        HttpCompilationResponse res = RestUtils
                .readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);
        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.rest.server.MavenRestHandlerTest.java

License:Apache License

@Test
public void get() {

    //Start preparation FS
    try {//from  w w  w  . j  av  a 2 s  . com
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();

        final String repoName = "myrepo";
        final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName),
                new HashMap<String, Object>() {
                    {
                        put("init", Boolean.TRUE);
                        put("internal", Boolean.TRUE);
                    }
                });

        ioService.startBatch(fs);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));

        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"),
                new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));

        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"),
                new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));

        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));

        ioService.endBatch();

        java.nio.file.Path tmpRootCloned = java.nio.file.Files.createTempDirectory("cloned");
        java.nio.file.Path tmpCloned = java.nio.file.Files
                .createDirectories(java.nio.file.Paths.get(tmpRootCloned.toString(), "dummy"));

        final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");

        final Git cloned = Git.cloneRepository()
                .setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false)
                .setDirectory(gitClonedFolder).call();

        assertThat(cloned).isNotNull();
        mavenRepoPath = java.nio.file.Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = java.nio.file.Paths.get(gitClonedFolder + "/dummy/");

        //END preparation FS

        //Test
        Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);
        MockHttpRequest request = MockHttpRequest.get("build/maven/");
        MockHttpResponse response = new MockHttpResponse();
        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        assertThat(response.getContentAsString()).isEqualTo("Apache Maven");
        //end test

        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.rest.server.MavenRestHandlerTest.java

License:Apache License

@Test
public void post() {
    //Start preparation FS
    try {//ww  w.j a  va 2s.  c  om
        fileSystemTestingUtils.setup();
        ioService = fileSystemTestingUtils.getIoService();

        final String repoName = "myrepo";
        final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git://" + repoName),
                new HashMap<String, Object>() {
                    {
                        put("init", Boolean.TRUE);
                        put("internal", Boolean.TRUE);
                    }
                });

        ioService.startBatch(fs);
        String pom = "target/test-classes/kjar-2-single-resources/pom.xml";
        if (!runIntoMavenCLI) {
            pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(pom).toPath())));

        String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        if (!runIntoMavenCLI) {
            personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"),
                new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath())));

        String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl";
        if (!runIntoMavenCLI) {
            simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl";
        }
        ioService.write(
                fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"),
                new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath())));

        String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        if (!runIntoMavenCLI) {
            kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml";
        }
        ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"),
                new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath())));

        ioService.endBatch();

        java.nio.file.Path tmpRootCloned = java.nio.file.Files.createTempDirectory("cloned");
        java.nio.file.Path tmpCloned = java.nio.file.Files
                .createDirectories(java.nio.file.Paths.get(tmpRootCloned.toString(), "dummy"));

        final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git");

        final Git cloned = Git.cloneRepository()
                .setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false)
                .setDirectory(gitClonedFolder).call();

        assertThat(cloned).isNotNull();
        mavenRepoPath = java.nio.file.Paths.get(System.getProperty("user.home"), ".m2", "repository");
        tmpRoot = java.nio.file.Paths.get(gitClonedFolder + "/dummy/");

        //END preparation FS

        Dispatcher dispatcher = new AsynchronousDispatcher(new ResteasyProviderFactory());
        ResteasyProviderFactory.setInstance(dispatcher.getProviderFactory());
        RegisterBuiltin.register(dispatcher.getProviderFactory());

        POJOResourceFactory noDefaults = new POJOResourceFactory(MavenRestHandler.class);
        dispatcher.getRegistry().addResourceFactory(noDefaults);

        MockHttpRequest request = MockHttpRequest.create("POST", "build/maven/");
        request.header("project", tmpRoot.toAbsolutePath().toString() + "/dummy").header("mavenrepo",
                mavenRepoPath.toAbsolutePath().toString());
        MockHttpResponse response = new MockHttpResponse();

        SynchronousExecutionContext synchronousExecutionContext = new SynchronousExecutionContext(
                (SynchronousDispatcher) dispatcher, request, response);
        request.setAsynchronousContext(synchronousExecutionContext);

        dispatcher.invoke(request, response);
        assertThat(response.getStatus()).isEqualTo(200);
        byte[] serializedCompilationResponse = response.getOutput();
        HttpCompilationResponse res = RestUtils
                .readDefaultCompilationResponseFromBytes(serializedCompilationResponse);
        assertThat(res).isNotNull();
        assertThat(res.getDependencies()).hasSize(4);
        assertThat(res.getTargetContent()).hasSize(3);

        tearDown();
    } catch (Exception e) {
        logger.error(e.getMessage());
    } finally {
        fileSystemTestingUtils.cleanup();
    }
}

From source file:org.komodo.rest.service.KomodoImportExportServiceTest.java

License:Open Source License

private void initGitRepository() throws Exception {
    String tmpDirPath = System.getProperty("java.io.tmpdir");
    File tmpDir = new File(tmpDirPath);

    long timestamp = System.currentTimeMillis();
    myGitDir = new File(tmpDir, "mygit-" + timestamp);
    assertTrue(myGitDir.mkdir());// www .j a  va2  s  .co m

    myGit = Git.init().setDirectory(myGitDir).setBare(true).call();
    assertNotNull(myGit);

    // Need to initialise the master branch
    // as jgit does not automatically create on
    File seedDir = new File(tmpDir, "seedDir-" + timestamp);
    Git seedGit = Git.cloneRepository().setURI(myGitDir.getAbsolutePath()).setDirectory(seedDir).call();

    File tweetVdbFile = new File(seedDir,
            TestUtilities.TWEET_EXAMPLE_NAME + TestUtilities.TWEET_EXAMPLE_SUFFIX);
    assertTrue(tweetVdbFile.createNewFile());
    FileUtils.write(TestUtilities.tweetExample(), tweetVdbFile);
    assertTrue(tweetVdbFile.length() > 0);

    File usStatesZipFile = new File(tmpDir, TestUtilities.US_STATES_DATA_SERVICE_NAME + ZIP_SUFFIX);
    FileUtils.write(TestUtilities.usStatesDataserviceExample(), usStatesZipFile);
    try (FileInputStream fis = new FileInputStream(usStatesZipFile)) {
        File usStatesDir = new File(seedDir, TestUtilities.US_STATES_DATA_SERVICE_NAME);
        usStatesDir.mkdir();
        FileUtils.zipExtract(fis, usStatesDir);
        usStatesZipFile.delete();
    }

    seedGit.add().addFilepattern(DOT).call();
    seedGit.commit().setMessage("First Commit").call();
    seedGit.push().call();

    FileUtils.removeDirectoryAndChildren(seedDir);

    //
    // Local git repository
    //
    String dirName = System.currentTimeMillis() + HYPHEN;
    gitRepoDest = new File(FileUtils.tempDirectory(), dirName);
    gitRepoDest.mkdir();
}

From source file:org.komodo.storage.git.GitStorageConnector.java

License:Open Source License

private void cloneRepository() throws Exception {
    File destination = new File(getDestination());
    File destGitDir = new File(destination, ".git");
    if (destGitDir.exists()) {
        git = Git.open(destination);/*w w w . java  2 s.c  om*/
    } else {
        git = Git.cloneRepository().setURI(getPath()).setDirectory(destination)
                .setTransportConfigCallback(transportConfigCallback).call();
    }
}

From source file:org.komodo.storage.git.TestGitStorageConnector.java

License:Open Source License

@Before
public void setup() throws Exception {
    String tmpDirPath = System.getProperty("java.io.tmpdir");
    tmpDir = new File(tmpDirPath);

    timestamp = System.currentTimeMillis();
    myGitDir = new File(tmpDir, "mygit-" + timestamp);
    assertTrue(myGitDir.mkdir());//from  w w  w. ja  va2s.co  m

    myGit = Git.init().setDirectory(myGitDir).setBare(true).call();
    assertNotNull(myGit);

    //
    // Create a clone to seed the repository with a file
    //
    File seedDir = new File(tmpDir, "seedDir-" + timestamp);
    Git seedGit = Git.cloneRepository().setURI(myGitDir.getAbsolutePath()).setDirectory(seedDir).call();

    // Adds a file into the seed repository
    File vdbFile = new File(seedDir, TEST_VDB_XML);
    assertTrue(vdbFile.createNewFile());
    FileUtils.write(TestUtilities.tweetExample(), vdbFile);
    assertTrue(vdbFile.length() > 0);

    File subDir = new File(seedDir, SUB_DIR);
    assertTrue(subDir.mkdir());

    File subDirVdbFile = new File(subDir, TEST_VDB_3_XML);
    assertTrue(subDirVdbFile.createNewFile());
    FileUtils.write(TestUtilities.tweetExample(), subDirVdbFile);
    assertTrue(subDirVdbFile.length() > 0);

    File usStatesZipFile = new File(tmpDir, TestUtilities.US_STATES_VDB_NAME + ZIP_SUFFIX);
    FileUtils.write(TestUtilities.usStatesDataserviceExample(), usStatesZipFile);
    try (FileInputStream fis = new FileInputStream(usStatesZipFile)) {
        File usStatesDir = new File(seedDir, TestUtilities.US_STATES_VDB_NAME);
        usStatesDir.mkdir();
        FileUtils.zipExtract(fis, usStatesDir);
        usStatesZipFile.delete();
    }

    seedGit.add().addFilepattern(DOT).call();
    seedGit.commit().setMessage("Adds Test Files").call();
    seedGit.push().call();

    FileUtils.removeDirectoryAndChildren(seedDir);
}

From source file:org.l2x6.srcdeps.core.impl.scm.JGitScm.java

License:Apache License

@Override
public void checkout(BuildRequest request) throws ScmException {

    Path dir = request.getProjectRootDirectory();
    if (!Files.exists(dir)) {
        try {/*from  ww w. j av a2 s  .  c om*/
            Files.createDirectories(dir);
        } catch (IOException e) {
            throw new ScmException(String.format("Could not create directory [%s]", dir), e);
        }
    }

    ScmException lastException = null;

    /* Try the urls one after another and exit on the first success */
    for (String url : request.getScmUrls()) {
        String useUrl = url.substring(SCM_GIT_PREFIX.length());
        log.info("Attempting to checkout version {} from SCM URL {}", request.getSrcVersion(), useUrl);
        SrcVersion srcVersion = request.getSrcVersion();

        CloneCommand cmd = Git.cloneRepository().setURI(useUrl).setDirectory(dir.toFile());

        switch (srcVersion.getWellKnownType()) {
        case branch:
        case tag:
            cmd.setBranch(srcVersion.getScmVersion());
            break;
        case revision:
            cmd.setCloneAllBranches(true);
            break;
        default:
            throw new IllegalStateException("Unexpected " + WellKnownType.class.getName() + " value '"
                    + srcVersion.getWellKnownType() + "'.");
        }

        try (Git git = cmd.call()) {
            git.checkout().setName(srcVersion.getScmVersion()).call();

            /*
             * workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=474093
             */
            git.getRepository().close();

            /* return on the first success */
            return;
        } catch (Exception e) {
            log.warn("Could not checkout version {} from SCM URL {}: {}: {}", request.getSrcVersion(), useUrl,
                    e.getClass().getName(), e.getMessage());
            lastException = new ScmException(String.format("Could not checkout from URL [%s]", useUrl), e);
        }
    }
    throw lastException;
}

From source file:org.megam.scm.git.GitRepository.java

License:Apache License

public GitRepository clone(String remotePath) throws SCMException {
    try {//from w ww. j  av a 2  s.  c  o m
        logger.debug("----> Repository Cloning start..");
        Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call();
        logger.debug("----> Repository Cloning completed..");
    } catch (InvalidRemoteException ire) {
        throw new SCMException("", ire);
    } catch (TransportException te) {
        throw new SCMException("", te);
    } catch (GitAPIException gae) {
        throw new SCMException("", gae);
    }
    return this;
}

From source file:org.ms123.common.git.GitServiceImpl.java

License:Open Source License

@RequiresRoles("admin")
public void cloneRepository(@PName("name") String name, @PName("fromUri") String fromUri) throws RpcException {
    File dir = null;/* www  . j a v  a 2 s  . c  o  m*/
    try {
        String gitSpace = System.getProperty("git.repos");
        dir = new File(gitSpace, name);
        if (dir.exists()) {
            throw new RpcException(ERROR_FROM_METHOD, 100,
                    "GitService.cloneRepository:Repo(" + name + ") exists");
        }
        CloneCommand ic = Git.cloneRepository();
        ic.setDirectory(dir);
        ic.setURI(fromUri);
        ic.call();
        FS fs = FS.detect();
        FileBasedConfig fbc = new FileBasedConfig(new File(gitSpace + "/" + name + "/.git/config"), fs);
        fbc.load();
        SimpleDateFormat sdf = new SimpleDateFormat(m_datePattern);
        sdf.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
        String created = sdf.format(new Date());
        fbc.setString("sw", null, "cloned", created);
        fbc.save();
        if (!isDataRepo(name)) {
            createStoreFile(gitSpace, name);
        }
        return;
    } catch (Exception e) {
        if (dir != null && dir.exists()) {
            try {
                forceDelete(dir);
            } catch (Exception ex) {
                e.printStackTrace();
            }
        }
        throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.createRepository:", e);
    } finally {
    }
}

From source file:org.mule.module.git.GitConnector.java

License:Open Source License

/**
 * Clone a repository into a new directory
 *
 * {@sample.xml ../../../doc/mule-module-git.xml.sample git:clone}
 *
 * @param uri The (possibly remote) repository to clone from.
 * @param bare True if you want a bare Git repository, false otherwise.
 * @param remote Name of the remote to keep track of the upstream repository.
 * @param branch Name of the local branch into which the remote will be cloned.
 * @param overrideDirectory Name of the directory to use for git repository
 *///www .  jav  a2s.  co m
@Processor
public void cloneRepository(String uri, @Optional @Default("false") boolean bare,
        @Optional @Default("origin") String remote, @Optional @Default("HEAD") String branch,
        @Optional String overrideDirectory) {
    File dir = resolveDirectory(overrideDirectory);

    if (!dir.exists()) {
        if (!dir.mkdirs()) {
            throw new RuntimeException("Directory " + dir.getAbsolutePath() + " cannot be created");
        }
    }

    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setBare(bare);
    cloneCommand.setDirectory(dir);
    cloneCommand.setRemote(remote);
    cloneCommand.setBranch(branch);
    cloneCommand.setURI(uri);

    try {
        Git git = cloneCommand.call();
    } catch (Exception e) {
        throw new RuntimeException("Cannot clone repository", e);
    }
}