package com.atlassian.bitbucket.mesh.git.builder.merge;

import com.atlassian.bitbucket.mesh.git.builder.GitProcessBuilder;

import javax.annotation.Nonnull;

public class DefaultGitSquashMergeBuilder
        extends AbstractGitMergeBuilder<GitSquashMergeBuilder>
        implements GitSquashMergeBuilder {

    public DefaultGitSquashMergeBuilder(GitProcessBuilder builder) {
        super(builder);
    }

    @Override
    protected void applyArguments() {
        if (ff == GitMergeFastForward.ONLY) {
            //Only --ff-only has any effect in conjunction with the --squash flag. --ff is accepted but does not
            //change the behaviour of the command. --no-ff triggers an error (although really it's the behaviour
            //--squash provides anyway, since it always creates a "merge" commit even on fast-forward merges) so
            //it is simply ignored here
            builder.argument(ff.getFlag());
        }
        builder.argument("--squash");

        super.applyArguments();
    }

    @Nonnull
    @Override
    protected GitSquashMergeBuilder self() {
        return this;
    }
}
