Example usage for org.eclipse.jgit.api PullCommand setProgressMonitor

List of usage examples for org.eclipse.jgit.api PullCommand setProgressMonitor

Introduction

In this page you can find the example usage for org.eclipse.jgit.api PullCommand setProgressMonitor.

Prototype

public PullCommand setProgressMonitor(ProgressMonitor monitor) 

Source Link

Document

Set progress monitor

Usage

From source file:com.rimerosolutions.ant.git.tasks.PullTask.java

License:Apache License

@Override
public void doExecute() {
    try {/*from ww w  .java2  s .com*/
        PullCommand pullCommand = git.pull().setRebase(rebase);

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

        setupCredentials(pullCommand);
        PullResult pullResult = pullCommand.call();

        if (!pullResult.isSuccessful()) {
            FetchResult fetchResult = pullResult.getFetchResult();
            GitTaskUtils.validateTrackingRefUpdates(MESSAGE_PULLED_FAILED, fetchResult.getTrackingRefUpdates());
            MergeStatus mergeStatus = pullResult.getMergeResult().getMergeStatus();

            if (!mergeStatus.isSuccessful()) {
                throw new BuildException(String.format(MESSAGE_PULLED_FAILED_WITH_STATUS, mergeStatus.name()));
            }
        }
    } catch (Exception e) {
        throw new GitBuildException(String.format(MESSAGE_PULLED_FAILED_WITH_URI, getUri()), e);
    }
}

From source file:com.romanenco.gitt.git.GitHelper.java

License:Open Source License

/**
 * Pull repo./*w  w w . ja  va2  s. co  m*/
 * 
 * @param localPath
 * @param user
 * @param password
 * @param pm
 * @throws GitError
 */
public static void pull(String localPath, String user, String password, ProgressMonitor pm) throws GitError {
    try {
        Git git = Git.open(new File(localPath));
        PullCommand pull = git.pull();
        pull.setProgressMonitor(pm);
        if ((user != null) && (password != null)) {
            UsernamePasswordCredentialsProvider access = new UsernamePasswordCredentialsProvider(user,
                    password);
            pull.setCredentialsProvider(access);
        }
        pull.call();
        return;
    } catch (DetachedHeadException e) {
        Log.e(TAG, "Detached head", e);
        GittApp.saveErrorTrace(e);
        throw new NoHeadError();
    } catch (InvalidRemoteException e) {
        Log.e(TAG, "InvalidRemote", e);
        GittApp.saveErrorTrace(e);
        throw new NotGitRepoError();
    } catch (TransportException e) {
        String trace = GittApp.saveErrorTrace(e);
        if (trace.indexOf("not authorized") != -1) {
            Log.e(TAG, "Auth", e);
            throw new AuthFailError();
        }
        Log.e(TAG, "Transport", e);
        throw new ConnectionError();
    } catch (GitAPIException e) {
        Log.e(TAG, "GitApi", e);
        GittApp.saveErrorTrace(e);
    } catch (IOException e) {
        Log.e(TAG, "IO", e);
        GittApp.saveErrorTrace(e);
    } catch (JGitInternalException e) {
        Log.e(TAG, "GitInternal", e);
        GittApp.saveErrorTrace(e);
        if (e.getCause() instanceof NotSupportedException) {
            throw new ConnectionError();
        }
    }
    throw new GitError();
}

From source file:net.mobid.codetraq.runnables.GitChecker.java

License:Open Source License

private void pull(String path) {
    LogService.writeMessage("GitChecker is trying to do a pull from " + _server.getServerAddress());
    //System.out.printf("GitChecker is trying to do a pull from %s%n", _server.getServerAddress());
    try {//from w ww. j  a  v a  2s  .  c  o  m
        File gitDir = new File(path);
        repo = new FileRepository(gitDir);
        if (mGit == null) {
            mGit = new Git(repo);
        }
        if (mGit.getRepository().getFullBranch() == null
                || Utilities.isHexString(mGit.getRepository().getFullBranch())) {
            attachHead(mGit, _server.getServerBranch());
        }
        PullCommand puller = mGit.pull();
        puller.setTimeout(60);
        puller.setProgressMonitor(new TextProgressMonitor());
        PullResult pullResult = puller.call();
        if (pullResult != null) {
            LogService.writeMessage("GitChecker has something to pull from " + _server.getServerAddress());
            FetchResult result = pullResult.getFetchResult();
            if (result.getTrackingRefUpdates().isEmpty()) {
                return;
            }
            showFetchResult(result, true);
        } else {
            LogService.writeMessage(
                    "GitChecker did not find anything to pull from " + _server.getServerAddress());
        }
    } catch (Exception ex) {
        LogService.getLogger(GitChecker.class.getName()).log(Level.SEVERE, null, ex);
        LogService.writeLog(Level.SEVERE, ex);
    }
}

From source file:net.orpiske.ssps.common.scm.git.GitSCM.java

License:Apache License

private void update(final File repositoryDir) throws ScmUpdateException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository;/*from ww  w.  ja  v  a  2  s. c o  m*/

    try {
        repository = builder.setGitDir(repositoryDir).readEnvironment().findGitDir().build();
    } catch (IOException e) {
        throw new ScmUpdateException(e.getMessage(), e);
    }

    Git git = new Git(repository);
    PullCommand pullCommand = git.pull();

    pullCommand.setProgressMonitor(new TextProgressMonitor());

    try {
        pullCommand.call();
    } catch (Exception e) {
        e.printStackTrace();

        throw new ScmUpdateException(e.getMessage(), e);
    }
}

From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java

License:Open Source License

/**
 * Pull from Remote/*from www. ja  v  a2 s. c o  m*/
 * @param localGitFolder
 * @param userName
 * @param userPassword
 * @return 
 * @throws IOException
 * @throws GitAPIException
 */
public static PullResult pullFromRemote(File localGitFolder, String userName, String userPassword,
        ProgressMonitor monitor) throws IOException, GitAPIException {
    try (Git git = Git.open(localGitFolder)) {
        PullCommand pullCommand = git.pull();
        pullCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword));
        pullCommand.setRebase(false); // Merge, not rebase
        pullCommand.setProgressMonitor(monitor);
        return pullCommand.call();
    }
}

From source file:org.eclipse.egit.core.op.PullOperation.java

License:Open Source License

public void execute(IProgressMonitor m) throws CoreException {
    if (pullResult != null)
        throw new CoreException(
                new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
    IProgressMonitor monitor;/*ww  w . j  av a 2s.  c om*/
    if (m == null)
        monitor = new NullProgressMonitor();
    else
        monitor = m;
    IWorkspaceRunnable action = new IWorkspaceRunnable() {
        public void run(IProgressMonitor mymonitor) throws CoreException {
            PullCommand pull = new Git(repository).pull();
            try {
                pull.setProgressMonitor(new EclipseGitProgressTransformer(mymonitor));
                pull.setTimeout(timeout);
                pullResult = pull.call();
            } catch (GitAPIException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            }
        }
    };
    // lock workspace to protect working tree changes
    ResourcesPlugin.getWorkspace().run(action, monitor);
}

From source file:org.jboss.forge.addon.git.GitUtilsImpl.java

License:Open Source License

@Override
public PullResult pull(final Git git, final int timeout) throws GitAPIException {
    PullCommand pull = git.pull();
    if (timeout >= 0)
        pull.setTimeout(timeout);//from   w  ww .  ja v  a 2s  . co  m
    pull.setProgressMonitor(new TextProgressMonitor());

    PullResult result = pull.call();
    return result;
}

From source file:org.jboss.forge.git.GitUtils.java

License:Open Source License

public static PullResult pull(final Git git, final int timeout) throws GitAPIException {
    PullCommand pull = git.pull();
    if (timeout >= 0)
        pull.setTimeout(timeout);//from   www. j a va 2 s.co  m
    pull.setProgressMonitor(new TextProgressMonitor());

    PullResult result = pull.call();
    return result;
}