Example usage for org.eclipse.jgit.api PullResult toString

List of usage examples for org.eclipse.jgit.api PullResult toString

Introduction

In this page you can find the example usage for org.eclipse.jgit.api PullResult toString.

Prototype

@SuppressWarnings("nls")
@Override
public String toString() 

Source Link

Usage

From source file:ch.sbb.releasetrain.git.GitRepoImpl.java

License:Apache License

private Git pull(Git git) throws GitAPIException {
    if (remoteBranchExists(git)) {
        PullResult result = git.pull().setStrategy(MergeStrategy.RECURSIVE)
                .setCredentialsProvider(this.credentialsProvider()).call();
        if (result.isSuccessful()) {
            return git;
        } else {//from www. j  av a  2s . co  m
            log.info(
                    "*** pulling git, not able to merge with MergeStrategy.RECURSIVE go for MergeStrategy.THEIRS");
            result = git.pull().setStrategy(MergeStrategy.THEIRS)
                    .setCredentialsProvider(this.credentialsProvider()).call();
            if (result.isSuccessful()) {
                return git;
            }
            throw new GitException("Pull failed: " + result.toString());
        }
    } else {
        return git;
    }
}

From source file:com.chungkwong.jgitgui.RemoteTreeItem.java

License:Open Source License

private void gitPull() {
    ProgressDialog progressDialog = new ProgressDialog(
            java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("PULLING"));
    PullCommand command = ((Git) getParent().getValue()).pull().setRemote(((RemoteConfig) getValue()).getName())
            .setProgressMonitor(progressDialog);
    new Thread(() -> {
        try {/*from  www  .j av  a2 s .  c o m*/
            PullResult result = command.call();
            HashSet<CommitTreeItem> commits = new HashSet<>();
            Platform.runLater(() -> {
                if (result.getFetchResult() != null) {
                    for (Ref ref : result.getFetchResult().getAdvertisedRefs())
                        try {
                            commits.add(new CommitTreeItem(((Git) getParent().getValue()).log()
                                    .addRange(ref.getObjectId(), ref.getObjectId()).call().iterator().next()));
                        } catch (Exception ex) {
                            Logger.getLogger(RemoteTreeItem.class.getName()).log(Level.SEVERE, null, ex);
                            Util.informUser(ex);
                        }
                }
                if (result.getMergeResult() != null
                        && result.getMergeResult().getMergeStatus().equals(MergeResult.MergeStatus.MERGED)) {
                    try {
                        ObjectId head = result.getMergeResult().getNewHead();
                        commits.add(new CommitTreeItem(((Git) getParent().getValue()).log().addRange(head, head)
                                .call().iterator().next()));
                    } catch (Exception ex) {
                        Logger.getLogger(RemoteTreeItem.class.getName()).log(Level.SEVERE, null, ex);
                        Util.informUser(ex);
                    }
                } else {
                    new Alert(Alert.AlertType.INFORMATION, result.toString(), ButtonType.CLOSE).show();
                }
                getParent().getChildren().filtered(item -> item instanceof LocalTreeItem)
                        .forEach((item) -> item.getChildren().addAll(commits));
            });
        } catch (Exception ex) {
            Logger.getLogger(GitTreeItem.class.getName()).log(Level.SEVERE, null, ex);
            Platform.runLater(() -> {
                progressDialog.hide();
                Util.informUser(ex);
            });
        }
    }).start();
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void pullRepository() {
    try (Git git = new Git(gitRepository)) {
        PullResult result = git.pull().call();

        System.out.println(result.toString());

    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }/*w  ww .  ja  v  a 2  s .co m*/
}

From source file:ezbake.deployer.publishers.openShift.RhcApplication.java

License:Apache License

/**
 * This will make sure that a directory is on disk for the git repository.  It will clone the git repo to the directory
 * if needed, or git pull the new contents if required.
 *
 * @return git repository created/retrieved from OpenShift with the remote pointing to OpenShift
 * @throws DeploymentException - on any exception getting it from git
 *//*from w ww.ja v a 2  s  .  c  om*/
public Git getOrCreateGitRepo() throws DeploymentException {
    String gitUrl = applicationInstance.getGitUrl();

    Files.createDirectories(appTmpDir);
    File gitDir = new File(appTmpDir, ".git");
    if (gitRepo != null || gitDir.exists() && gitDir.isDirectory()) {
        try {
            Git git = gitRepo != null ? gitRepo : Git.open(appTmpDir);
            // stash to get to a clean state of git dir so that we can pull without conflicts
            git.stashCreate();
            git.stashDrop();
            PullCommand pullCommand = git.pull();
            if (gitCredentialsProvider != null)
                pullCommand.setCredentialsProvider(gitCredentialsProvider);
            PullResult result = pullCommand.call();
            if (!result.isSuccessful())
                throw new DeploymentException("Git pull was not successful: " + result.toString());
            setGitRepo(git);
            return git;
        } catch (IOException | GitAPIException e) {
            log.error("Error opening existing cached git repo", e);
            throw new DeploymentException("Error opening existing cached git repo: " + e.getMessage());
        }
    } else {
        try {
            log.info("Cloning to " + appTmpDir.toString());
            CloneCommand cloneCommand = Git.cloneRepository().setURI(gitUrl).setTimeout(10000)
                    .setDirectory(appTmpDir);
            if (gitCredentialsProvider != null)
                cloneCommand.setCredentialsProvider(gitCredentialsProvider);
            gitRepo = cloneCommand.call();
            log.info("Cloned to directory: "
                    + gitRepo.getRepository().getDirectory().getParentFile().getAbsolutePath());
            return gitRepo;
        } catch (GitAPIException | JGitInternalException e) {
            log.error("Error cloning repository from OpenShift", e);
            throw new DeploymentException("Error cloning repository from OpenShift: " + e.getMessage());
        }
    }
}

From source file:fr.duminy.tools.jgit.JGitToolbox.java

License:Open Source License

public String track(Parameters parameters) throws GitToolboxException {
    try {/* w w w.j ava 2s.co  m*/
        Git targetGit = Git.open(parameters.getGitDirectory());
        ProgressMonitor progressMonitor = new TextProgressMonitor();
        PullCommand pullCommand = targetGit.pull().setProgressMonitor(progressMonitor);
        PullResult result = pullCommand.call();
        System.out.println(result);
        if (!result.isSuccessful()) {
            throw new GitToolboxException("Failed to update tracking branch : " + result.toString());
        }

        MergeResult.MergeStatus mergeStatus = result.getMergeResult().getMergeStatus();
        if (!ALREADY_UP_TO_DATE.equals(mergeStatus) && !FAST_FORWARD.equals(mergeStatus)) {
            throw new GitToolboxException("Failed to update tracking branch : " + result.toString());
        }

        return targetGit.getRepository().getRef(Constants.HEAD).getName();
    } catch (Exception e) {
        throw new GitToolboxException("Error while updating tracking branch", e);
    }
}

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

License:Open Source License

public void pull(@PName("name") String name) throws RpcException {
    try {/*from ww  w  .  j  av  a  2 s .  c om*/
        String gitSpace = System.getProperty("git.repos");
        File dir = new File(gitSpace, name);
        if (!dir.exists()) {
            throw new RpcException(ERROR_FROM_METHOD, 100, "GitService.pull:Repo(" + name + ") not exists");
        }
        Git git = Git.open(dir);
        PullCommand pull = git.pull();
        PullResult result = pull.call();
        debug(result.toString());
        return;
    } catch (Exception e) {
        throw new RpcException(ERROR_FROM_METHOD, INTERNAL_SERVER_ERROR, "GitService.pull:", e);
    } finally {
    }
}