Example usage for org.eclipse.jgit.api MergeResult MergeResult

List of usage examples for org.eclipse.jgit.api MergeResult MergeResult

Introduction

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

Prototype

public MergeResult(List<String> checkoutConflicts) 

Source Link

Document

Creates a new result that represents a checkout conflict before the operation even started for real.

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 {//  w w w. ja  v a2 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);
    }
}