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

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

Introduction

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

Prototype

public RebaseCommand rebase() 

Source Link

Document

Return a command object to execute a Rebase command

Usage

From source file:to.sauerkraut.krautadmin.core.Toolkit.java

License:Open Source License

public static boolean updateFromGit(final File repositoryDirectory, final URI repositoryUri) throws Exception {
    final String unexpectedExceptionText = "incremental plugin-update from git failed";
    final String upstream = "refs/remotes/origin/master";
    boolean hasUpdated = false;
    Git gitRepo = null;

    try {/*ww  w .java 2  s  .  c  o m*/
        gitRepo = Git.open(repositoryDirectory);
        // first reset local changes
        gitRepo.reset().setMode(ResetCommand.ResetType.HARD).call();
        LOG.info("starting incremental plugin-update from git...");
        gitRepo.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call();
        final RebaseResult rebaseResult = gitRepo.rebase().setStrategy(MergeStrategy.THEIRS)
                .setUpstream(upstream).setUpstreamName(upstream).call();
        final Status rebaseStatus = rebaseResult.getStatus();
        if (rebaseStatus.isSuccessful()) {
            if (!(Status.UP_TO_DATE.equals(rebaseStatus))) {
                hasUpdated = true;
            }
        } else {
            throw new WTFException(unexpectedExceptionText);
        }

        if (hasUpdated) {
            LOG.info("incremental plugin-update from git successful");
        } else {
            LOG.info("plugin-files are up-to-date");
        }
    } finally {
        try {
            if (gitRepo != null) {
                gitRepo.close();
            }
        } catch (Exception closex) {
            LOG.debug("closing git repo failed");
        }
    }

    return hasUpdated;
}