Java Code Examples for org.eclipse.jgit.api.CloneCommand#setBranch()

The following examples show how to use org.eclipse.jgit.api.CloneCommand#setBranch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitWrapper.java    From Stringlate with MIT License 5 votes vote down vote up
public static boolean cloneRepo(final String uri, final File cloneTo,
                                final String branch,
                                final GitCloneProgressCallback callback) {
    Git result = null;

    try {
        final CloneCommand clone = Git.cloneRepository()
                .setURI(uri).setDirectory(cloneTo)
                .setBare(false).setRemote(REMOTE_NAME).setNoCheckout(false)
                .setCloneAllBranches(false).setCloneSubmodules(false)
                .setProgressMonitor(callback);

        if (!branch.isEmpty()) {
            if (branch.contains("/")) {
                clone.setBranch(branch.substring(branch.lastIndexOf('/') + 1));
            } else {
                clone.setBranch(branch);
            }
        }

        result = clone.call();
        return true;
    } catch (GitAPIException e) {
        e.printStackTrace();
    } finally {
        if (result != null) {
            result.close();
        }
    }
    return false;
}
 
Example 2
Source File: ProjectWebsiteTest.java    From jbake with MIT License 5 votes vote down vote up
private void cloneJbakeWebsite() throws GitAPIException {
    CloneCommand cmd = Git.cloneRepository();
    cmd.setBare(false);
    cmd.setBranch("master");
    cmd.setRemote("origin");
    cmd.setURI(WEBSITE_REPO_URL);
    cmd.setDirectory(projectFolder);

    cmd.call();

    assertThat(new File(projectFolder,"README.md").exists()).isTrue();
}
 
Example 3
Source File: CloneTask.java    From ant-git-tasks with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() {
        try {
                CloneCommand cloneCommand = new CloneCommand();

                if (branchToTrack != null) {
                        cloneCommand.setBranch(branchToTrack);
                }

                if (!branchNames.isEmpty()) {
                        cloneCommand.setBranchesToClone(branchNames);
                }

                cloneCommand.setURI(getUri()).
                        setBare(bare).
                        setCloneAllBranches(cloneAllBranches).
                        setCloneSubmodules(cloneSubModules).
                        setNoCheckout(noCheckout).
                        setDirectory(getDirectory());

                setupCredentials(cloneCommand);

                if (getProgressMonitor() != null) {
                        cloneCommand.setProgressMonitor(getProgressMonitor());
                }

                cloneCommand.call();
        }
        catch (Exception e) {
                throw new GitBuildException(String.format(MESSAGE_CLONE_FAILED, getUri()), e);
        }
}
 
Example 4
Source File: MaestroAgent.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(final AgentSourceRequest note) {
    logger.info("Source request arrived");

    final String sourceUrl = note.getSourceUrl();
    final String branch = note.getBranch();

    if (branch == null) {
        logger.info("Preparing to download code from {}", sourceUrl);
    }
    else {
        logger.info("Preparing to download code from {} from branch {}", sourceUrl, branch);
    }
    final String projectDir = UUID.randomUUID().toString();

    final File repositoryDir = new File(sourceRoot + File.separator + projectDir + File.separator);

    if (!repositoryDir.exists()) {
        if (!repositoryDir.mkdirs()) {
            logger.warn("Unable to create directory: {}", repositoryDir);
        }
    }

    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(sourceUrl);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(NullProgressMonitor.INSTANCE);


    if (branch != null) {
        cloneCommand.setBranch(branch);
    }

    try {
        cloneCommand.call();
        logger.info("Source directory for project created at {}", repositoryDir);
        extensionPoints.add(new ExtensionPoint(new File(repositoryDir, "requests"), true));

        getClient().replyOk(note);
    } catch (GitAPIException e) {
        logger.error("Unable to clone repository: {}", e.getMessage(), e);
        getClient().replyInternalError(note,"Unable to clone repository: %s", e.getMessage());
    }
}