Example usage for org.eclipse.jgit.api MergeCommand setSquash

List of usage examples for org.eclipse.jgit.api MergeCommand setSquash

Introduction

In this page you can find the example usage for org.eclipse.jgit.api MergeCommand setSquash.

Prototype

public MergeCommand setSquash(boolean squash) 

Source Link

Document

If true, will prepare the next commit in working tree and index as if a real merge happened, but do not make the commit or move the HEAD.

Usage

From source file:org.flowerplatform.web.git.operation.MergeOperation.java

License:Open Source License

public void execute() {
    ProgressMonitor monitor = ProgressMonitor.create(GitPlugin.getInstance().getMessage("git.merge"), channel);

    try {//www  .j  a  v a  2  s . c o m
        monitor.beginTask(GitPlugin.getInstance().getMessage("git.merge.title", new Object[] { refName }), 3);
        //         IProject[] validProjects = GitPlugin.getInstance().getUtils().getValidProjects(repository);
        //         
        //         GitPlugin.getInstance().getGitUtils().backupProjectConfigFiles(null, validProjects);
        //                  
        Git git = new Git(repository);
        monitor.worked(1);
        MergeCommand merge;

        FastForwardMode ffmode = FastForwardMode.FF;
        Ref ref = repository.getRef(refName);
        if (ref != null) {
            merge = git.merge().include(ref).setFastForward(ffmode);
        } else {
            merge = git.merge().include(ObjectId.fromString(refName)).setFastForward(ffmode);
        }
        merge.setSquash(squash);

        mergeResult = (MergeResult) GitPlugin.getInstance().getUtils().runGitCommandInUserRepoConfig(repository,
                merge);
        monitor.worked(1);

        //         GitPlugin.getInstance().getUtils().refreshValidProjects(validProjects, new SubProgressMonitor(monitor, 1));      
    } catch (NoHeadException e) {
        channel.appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        GitPlugin.getInstance().getMessage("git.merge.mergeOperation.mergeFailedNoHead"),
                        DisplaySimpleMessageClientCommand.ICON_ERROR));
    } catch (ConcurrentRefUpdateException e) {
        channel.appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        GitPlugin.getInstance().getMessage("git.merge.mergeOperation.mergeFailedRefUpdate"),
                        DisplaySimpleMessageClientCommand.ICON_ERROR));
    } catch (CheckoutConflictException e) {
        mergeResult = new MergeResult(e.getConflictingPaths());
    } catch (GitAPIException e) {
        channel.appendOrSendCommand(new DisplaySimpleMessageClientCommand(
                CommonPlugin.getInstance().getMessage("error"), e.getLocalizedMessage(),
                e.getCause().getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
    } catch (Exception e) {
        channel.appendOrSendCommand(
                new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"),
                        e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR));
    } finally {
        monitor.done();
        //         GitPlugin.getInstance().getUtils().restoreProjectConfigFiles(repository, null);
    }
}