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

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

/**
 * Describes the possible modes which can be used when creating a new branch using {@code git checkout}.
 */
public enum GitCheckoutCreateBranchMode {

    /**
     * Create a new branch, failing if a branch already exists with the desired name. If an explicit mode is not
     * specified when {@link GitCheckoutBuilder#branch(String, String) creating a new branch}, this mode will be
     * used by default.
     */
    CREATE("-b"),
    /**
     * Create a new branch, or reset the existing branch if the desired name is already in use.
     */
    CREATE_OR_RESET("-B"),
    /**
     * Create a new branch using the <i>contents</i> of the {@code startPoint}, but for which the first
     * commit will be a new root commit.
     * <p>
     * This mode should be used with caution. Repositories should generally only have a single root commit, and
     * the "need" for additional roots may be better served by creating separate <i>repositories</i> instead.
     */
    ORPHAN("--orphan");

    private final String flag;

    GitCheckoutCreateBranchMode(String flag) {
        this.flag = requireNonNull(flag, "flag");
    }

    /**
     * @return the command line flag to activate this mode
     */
    @Nonnull
    public String getFlag() {
        return flag;
    }
}
