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

public enum GitFetchTagMode {

    /**
     * Fetches tags referencing any object reachable from a fetched head. This is referred to in the Git documentation
     * as "tag following". It means that, for example, {@code git fetch origin refs/heads/master} can end up fetching
     * some number of tags, even though they were not requested, so long as those tags can be satisfied by the objects
     * reachable from "refs/heads/master".
     */
    DEFAULT,
    /**
     * Disables "tag following", ensuring only explicitly-requested refs (potentially including tags) are updated.
     */
    NO_TAGS("--no-tags"),
    /**
     * Explicitly fetches all remote tags. This is the same as explicitly passing {@code refs/tags/*:refs/tags/*} as
     * a {@link GitFetchBuilder#refspec(String) refspec}, meaning it will override configured default refspecs.
     * <p>
     * In addition to the obvious behaviour of creating new local tags for new remote tags, this also has a (largely
     * undocumented) side effect of updating any local tag which matches the name of a remote tag but does not refer
     * to the same object. <i>This is done even if non-fast-forward updates are not requested.</i>.
     */
    TAGS("--tags");

    private final String flag;

    GitFetchTagMode() {
        flag = null;
    }

    GitFetchTagMode(String flag) {
        this.flag = flag;
    }

    public String getFlag() {
        return flag;
    }

    public boolean isFlagged() {
        return flag != null;
    }
}
