Example usage for org.eclipse.jgit.api CloneCommand setNoCheckout

List of usage examples for org.eclipse.jgit.api CloneCommand setNoCheckout

Introduction

In this page you can find the example usage for org.eclipse.jgit.api CloneCommand setNoCheckout.

Prototype

public CloneCommand setNoCheckout(boolean noCheckout) 

Source Link

Document

Set whether to skip checking out a branch

Usage

From source file:com.microsoft.tfs.client.eclipse.ui.egit.importwizard.CloneGitRepositoryCommand.java

License:Open Source License

private boolean cloneRepository(final IProgressMonitor progressMonitor) {
    final CloneCommand cloneRepository = Git.cloneRepository();

    cloneRepository.setCredentialsProvider(credentialsProvider);
    cloneRepository.setProgressMonitor(new CloneProgress(progressMonitor));

    final File workFolder = new File(workingDirectory);
    if (!workFolder.exists()) {
        if (!workFolder.mkdirs()) {
            if (!workFolder.isDirectory()) {
                final String errorMessageFormat = "Cannot create {0} directory"; //$NON-NLS-1$
                throw new RuntimeException(MessageFormat.format(errorMessageFormat, workingDirectory));
            }//  w w w  .  j av a  2  s.c  om
        }
    }
    cloneRepository.setDirectory(new File(workingDirectory));

    cloneRepository.setRemote(remoteName);
    cloneRepository.setURI(URIUtils.encodeQueryIgnoringPercentCharacters(repositoryUrl.toString()));

    cloneRepository.setCloneAllBranches(true);
    cloneRepository.setBranchesToClone(Arrays.asList(refs));
    cloneRepository.setBranch(defaultRef);

    cloneRepository.setNoCheckout(false);
    cloneRepository.setTimeout(timeout);
    cloneRepository.setCloneSubmodules(cloneSubmodules);

    try {
        cloneRepository.call();
        if (progressMonitor.isCanceled()) {
            throw new CanceledException();
        }

        registerClonedRepository(workingDirectory);
    } catch (final CanceledException e) {
        throw e;
    } catch (final Exception e) {
        logger.error("Error cloning repository:", e); //$NON-NLS-1$
        errorMessage = e.getLocalizedMessage();
        return false;
    }

    return true;
}

From source file:org.ajoberstar.gradle.git.tasks.GitClone.java

License:Apache License

/**
 * Clones a Git repository as configured.
 *//* w  w w .  j a v  a2 s . c  o m*/
@TaskAction
public void cloneRepo() {
    CloneCommand cmd = Git.cloneRepository();
    TransportAuthUtil.configure(cmd, this);
    cmd.setURI(getUri().toString());
    cmd.setRemote(getRemote());
    cmd.setBare(getBare());
    cmd.setNoCheckout(!getCheckout());
    cmd.setBranch(getRef());
    cmd.setBranchesToClone(getBranchesToClone());
    cmd.setCloneAllBranches(getCloneAllBranches());
    cmd.setDirectory(getDestinationDir());
    try {
        cmd.call();
    } catch (InvalidRemoteException e) {
        throw new GradleException("Invalid remote specified: " + getRemote(), e);
    } catch (TransportException e) {
        throw new GradleException("Problem with transport.", e);
    } catch (GitAPIException e) {
        throw new GradleException("Problem with clone.", e);
    }
    //TODO add progress monitor to log progress to Gradle status bar
}

From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java

License:Open Source License

private static Git cloneRepository(SetupTaskContext context, File workDir, String checkoutBranch,
        String remoteName, String remoteURI, boolean recursive, IProgressMonitor monitor) throws Exception {
    context.log("Cloning Git repo " + remoteURI + " to " + workDir);

    CloneCommand command = Git.cloneRepository();
    command.setNoCheckout(true);
    command.setURI(remoteURI);/*w  w  w. ja va 2s.  co  m*/
    command.setRemote(remoteName);
    command.setBranchesToClone(Collections.singleton(checkoutBranch));
    command.setDirectory(workDir);
    command.setTimeout(60);
    command.setProgressMonitor(new EclipseGitProgressTransformer(monitor));
    return command.call();
}

From source file:org.flowerplatform.web.git.GitService.java

License:Open Source License

@RemoteInvocation
public boolean cloneRepository(final ServiceInvocationContext context, List<PathFragment> selectedPath,
        String repositoryUrl, final List<String> selectedBranches, final String remoteName,
        final boolean cloneAllBranches) {
    tlCommand.set((InvokeServiceMethodServerCommand) context.getCommand());

    final URIish uri;
    try {//w  w w.j  a  v  a2s . c  o  m
        uri = new URIish(repositoryUrl.trim());
    } catch (URISyntaxException e) {
        context.getCommunicationChannel().appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getReason(), DisplaySimpleMessageClientCommand.ICON_ERROR));
        return false;
    }

    @SuppressWarnings("unchecked")
    final Pair<File, Object> node = (Pair<File, Object>) GenericTreeStatefulService
            .getNodeByPathFor(selectedPath, null);

    File gitReposFile = GitPlugin.getInstance().getUtils().getGitRepositoriesFile(node.a);
    final File mainRepo = GitPlugin.getInstance().getUtils()
            .getMainRepositoryFile(new File(gitReposFile, uri.getHumanishName()), true);

    final ProgressMonitor monitor = ProgressMonitor.create(
            GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri),
            context.getCommunicationChannel());
    monitor.beginTask(GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri), 2);

    Job job = new Job(
            MessageFormat.format(GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri), uri)) {
        @Override
        protected IStatus run(IProgressMonitor m) {
            Repository repository = null;
            try {
                CloneCommand cloneRepository = Git.cloneRepository();

                cloneRepository.setNoCheckout(true);
                cloneRepository.setDirectory(mainRepo);
                cloneRepository.setProgressMonitor(new GitProgressMonitor(new SubProgressMonitor(monitor, 1)));
                cloneRepository.setRemote(remoteName);
                cloneRepository.setURI(uri.toString());
                cloneRepository.setTimeout(30);
                cloneRepository.setCloneAllBranches(cloneAllBranches);
                cloneRepository.setCloneSubmodules(false);
                if (selectedBranches.size() > 0) {
                    cloneRepository.setBranchesToClone(selectedBranches);
                }

                Git git = cloneRepository.call();
                repository = git.getRepository();

                // notify clients about changes
                dispatchContentUpdate(node);

                monitor.worked(1);
            } catch (Exception e) {
                if (repository != null)
                    repository.close();
                GitPlugin.getInstance().getUtils().delete(mainRepo.getParentFile());

                if (monitor.isCanceled()) {
                    return Status.OK_STATUS;
                }
                if (GitPlugin.getInstance().getUtils().isAuthentificationException(e)) {
                    openLoginWindow();
                    return Status.OK_STATUS;
                }
                logger.debug(GitPlugin.getInstance().getMessage("git.cloneWizard.error",
                        new Object[] { mainRepo.getName() }), e);
                context.getCommunicationChannel()
                        .appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                                CommonPlugin.getInstance().getMessage("error"),
                                GitPlugin.getInstance().getMessage("git.cloneWizard.error",
                                        new Object[] { mainRepo.getName() }),
                                DisplaySimpleMessageClientCommand.ICON_ERROR));

                return Status.CANCEL_STATUS;
            } finally {
                monitor.done();
                if (repository != null) {
                    repository.close();
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
    return true;
}

From source file:org.jabylon.team.git.GitTeamProvider.java

License:Open Source License

@Override
public void checkout(ProjectVersion project, IProgressMonitor monitor) throws TeamProviderException {
    try {/*  w  w  w.  ja  va2  s .c om*/
        SubMonitor subMon = SubMonitor.convert(monitor, 100);
        subMon.setTaskName("Checking out");
        subMon.worked(20);
        File repoDir = new File(project.absoluteFilePath().path());
        CloneCommand clone = Git.cloneRepository();
        clone.setBare(false);
        clone.setNoCheckout(false);
        // if(!"master".equals(project.getName()))
        clone.setBranch("refs/heads/" + project.getName());
        // clone.setCloneAllBranches(true);
        clone.setBranchesToClone(Collections.singletonList("refs/heads/" + project.getName()));

        clone.setDirectory(repoDir);

        URI uri = project.getParent().getRepositoryURI();
        if (!"https".equals(uri.scheme()) && !"http".equals(uri.scheme()))
            clone.setTransportConfigCallback(createTransportConfigCallback(project.getParent()));
        clone.setCredentialsProvider(createCredentialsProvider(project.getParent()));
        clone.setURI(stripUserInfo(uri).toString());
        clone.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(70)));

        clone.call();
        subMon.done();
        if (monitor != null)
            monitor.done();
    } catch (TransportException e) {
        throw new TeamProviderException(e);
    } catch (InvalidRemoteException e) {
        throw new TeamProviderException(e);
    } catch (GitAPIException e) {
        throw new TeamProviderException(e);
    }
}

From source file:org.jenkinsci.git.CloneOperation.java

License:Open Source License

public Repository invoke(File file, VirtualChannel channel) throws IOException {
    String directory = repo.getDirectory();
    File gitDir;/*from  ww  w.  ja  v  a2  s.com*/
    if (directory == null || directory.length() == 0 || ".".equals(directory))
        gitDir = file;
    else
        gitDir = new File(file, directory);

    CloneCommand clone = Git.cloneRepository();
    clone.setURI(repo.getUri());
    clone.setCloneAllBranches(false);
    clone.setBranchesToClone(Collections.singletonList(repo.getBranch()));
    clone.setDirectory(gitDir);
    clone.setNoCheckout(true);
    return clone.call().getRepository();
}

From source file:us.rader.dinodocs.GitPuller.java

License:Apache License

/**
 * Clone the "master" branch from specified remote repository to the
 * specified local directory.//  w  w  w . j  a v  a2s . c  o  m
 * 
 * @param remoteRepository
 *            Remote repository {@link URL}
 * 
 * @param branch
 *            Branch name
 * 
 * @param localRepository
 *            File system path to local repository
 * 
 * @throws Exception
 *             Thrown if check out fails
 */
private void cloneRepository(URI remoteRepository, String branch, File localRepository) throws Exception {

    String externalForm = remoteRepository.toString();
    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setDirectory(localRepository);
    cloneCommand.setURI(externalForm);
    cloneCommand.setNoCheckout(false);
    cloneCommand.setCloneAllBranches(false);
    List<String> branches = new ArrayList<String>();
    branches.add(branch);
    cloneCommand.setBranchesToClone(branches);
    cloneCommand.setBranch(branch);

    try (Git git = cloneCommand.call()) {

        if (logger.isLoggable(Level.FINE)) {

            logger.logp(Level.FINE, getClass().getName(), "cloneRepository()", //$NON-NLS-1$
                    MessageFormat.format("cloned {1} of {0} to \"{0}\"", externalForm, branch, //$NON-NLS-1$
                            localRepository.getCanonicalPath()));

        }
    }
}