<commit_before>package gr.jchrist.gitextender;

import git4idea.commands.Git;
import git4idea.repo.GitBranchTrackInfo;
import git4idea.repo.GitRepository;
import gr.jchrist.gitextender.configuration.GitExtenderSettings;
import gr.jchrist.gitextender.handlers.*;
import org.jetbrains.annotations.NotNull;

/**
 * @author jchrist
 * @since 2016/03/27
 */
public class BranchUpdater {
    private final Git git;
    private final GitRepository repo;

    private final String repoName;
    private final String remoteBranchName;
    private final String localBranchName;
    private final BranchUpdateResult branchUpdateResult;
    private final GitExtenderSettings gitExtenderSettings;
    private MergeState mergeState;

    public BranchUpdater(
            Git git, GitRepository repo, String repoName,
            GitBranchTrackInfo info, GitExtenderSettings gitExtenderSettings) {
        this.git = git;
        this.repo = repo;
        this.repoName = repoName;

        this.remoteBranchName = info.getRemoteBranch().getNameForLocalOperations();
        this.localBranchName = info.getLocalBranch().getName();
        this.branchUpdateResult = new BranchUpdateResult();
        this.gitExtenderSettings = gitExtenderSettings;
    }

    @NotNull
    public BranchUpdateResult update() {
        checkout();
        if (!branchUpdateResult.isCheckoutSuccess()) {
            return this.branchUpdateResult;
        }

        merge();
        return this.branchUpdateResult;
    }

    protected void checkout() {
        branchUpdateResult.checkoutResult =
                new CheckoutHandler(git, repo.getProject(), repo.getRoot(), localBranchName)
                        .checkout();
    }

    protected void merge() {
        //let's prepare for the merge: find what files we have now
        prepareMerge();

        mergeFastForwardOnly();
        if (!branchUpdateResult.isMergeSuccess()) {
            // this is controlled with a user setting flag,
            // because it might be dangerous in case abort fails
            if (Boolean.TRUE.equals(gitExtenderSettings.getAttemptMergeAbort())) {
                mergeAbortIfFailed();
            }
        }

        if (branchUpdateResult.isMergeSuccess()) {
            afterMerge();
        }
    }

    protected void mergeFastForwardOnly() {
        branchUpdateResult.mergeFastForwardResult =
                new FastForwardOnlyMerger(git, repo.getProject(), repo.getRoot(), remoteBranchName)<commit_msg>added "logging" whether merge-with-abort-on-failure is attempted or not<commit_after>package gr.jchrist.gitextender;

import git4idea.commands.Git;
import git4idea.repo.GitBranchTrackInfo;
import git4idea.repo.GitRepository;
import gr.jchrist.gitextender.configuration.GitExtenderSettings;
import gr.jchrist.gitextender.handlers.*;
import org.jetbrains.annotations.NotNull;

/**
 * @author jchrist
 * @since 2016/03/27
 */
public class BranchUpdater {
    private final Git git;
    private final GitRepository repo;

    private final String repoName;
    private final String remoteBranchName;
    private final String localBranchName;
    private final BranchUpdateResult branchUpdateResult;
    private final GitExtenderSettings gitExtenderSettings;
    private MergeState mergeState;

    public BranchUpdater(
            Git git, GitRepository repo, String repoName,
            GitBranchTrackInfo info, GitExtenderSettings gitExtenderSettings) {
        this.git = git;
        this.repo = repo;
        this.repoName = repoName;

        this.remoteBranchName = info.getRemoteBranch().getNameForLocalOperations();
        this.localBranchName = info.getLocalBranch().getName();
        this.branchUpdateResult = new BranchUpdateResult();
        this.gitExtenderSettings = gitExtenderSettings;
    }

    @NotNull
    public BranchUpdateResult update() {
        checkout();
        if (!branchUpdateResult.isCheckoutSuccess()) {
            return this.branchUpdateResult;
        }

        merge();
        return this.branchUpdateResult;
    }

    protected void checkout() {
        branchUpdateResult.checkoutResult =
                new CheckoutHandler(git, repo.getProject(), repo.getRoot(), localBranchName)
                        .checkout();
    }

    protected void merge() {
        //let's prepare for the merge: find what files we have now
        prepareMerge();

        mergeFastForwardOnly();
        if (!branchUpdateResult.isMergeSuccess()) {
            // this is controlled with a user setting flag,
            // because it might be dangerous in case abort fails
            if (Boolean.TRUE.equals(gitExtenderSettings.getAttemptMergeAbort())) {
                System.out.println("fast-forward merge failed, attempting simple merge");
                mergeAbortIfFailed();
            } else {
                System.out.println("fast-forward merge failed, NOT attempting simple merge");
            }
        }

        if (branchUpdateResult.isMergeSuccess()) {
            afterMerge();
        }
    }

    protected void mergeFastForwardOnly() {
        branchUpdateResult.mergeFastForwardResult =
                new FastForwardOnlyMerger(git, repo.getProject(), repo.getRoot(), remoteBranchName)
{'fraction_non_alphanumeric': 0.08315769304464457, 'fraction_numerical': 0.00421536692853037, 'mean_word_length': 2.7285714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7388091', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1317, 'n_words': 322}