# (C) 2011-2025 magicant

# Completion script for the "git-branch" command.
# Supports Git 2.48.1.

function completion/git-branch {
        WORDS=(git branch "${WORDS[2,-1]}")
        command -f completion//reexecute
}

function completion/git::branch:arg {

        OPTIONS=( #>#
        "--abbrev:; specify the number of commit ID digits to print"
        "a --all; print local and remote-tracking branches"
        "--color::; show symbols in color"
        "--column::; columnize output"
        "--contains; show branches that contain the specified commit only"
        "C; copy a branch, overwriting an existing branch"
        "c --copy; copy a branch"
        "l --create-reflog; enable reflog for the new branch"
        "D; delete a branch that has not been merged"
        "d --delete; delete a branch"
        "--edit; edit the branch explanation with an editor"
        "f --force; overwrite an existing branch"
        "--format:; specify an output format"
        "i --ignore-case; sort and filter branches case-insensitively"
        "l --list; list branches matching the operand pattern"
        "M; rename a branch, overwriting an existing branch"
        "--merged; show branches that are contained in the specified commit only"
        "m --move; rename a branch"
        "--no-abbrev; print full commit IDs"
        "--no-color; like --color=never"
        "--no-column; print branches line by line"
        "--no-contains; show branches that don't contain the specified commit"
        "--no-merged; show branches that aren't contained in the specified commit only"
        "--no-track; create a non-tracking branch"
        "--omit-empty; don't print empty items"
        "--points-at; show branches that point at the specified commit"
        "q --quiet; print error messages only"
        "--recurse-submodules; propagate branches in submodules"
        "r --remotes; print or delete remote-tracking branches"
        "--set-upstream; like --track, but don't move HEAD"
        "u: --set-upstream-to:; set the upstream to the specified one"
        "--show-current; show the current branch name"
        "--sort:; specify the sort order"
        "t:: --track::; create a remote-tracking branch"
        "--unset-upstream; remove the upstream"
        "v --verbose; print commit ID and summary for each branch"
        ) #<#

        command -f completion//parseoptions -n
        case $ARGOPT in
                (-)
                        command -f completion//completeoptions
                        ;;
                (--abbrev)
                        ;;
                (t|--color|--column|--sort|--track)
                        command -f completion/git::$ARGOPT:arg
                        ;;
                (--format)
                        #TODO
                        ;;
                (u|--set-upstream-to)
                        command -f completion/git::completeref --remotes
                        ;;
                ('')
                        typeset i=2 all=false delete=false
                        while [ $i -le ${WORDS[#]} ]; do
                                case ${WORDS[i]} in
                                (--)
                                        i=$((i+1))
                                        break
                                        ;;
                                (--merged|--no-merged|--contains)
                                        all=true
                                        break
                                        ;;
                                (--*)
                                        i=$((i+1))
                                        ;;
                                (-*[Dd]*)
                                        delete=true
                                        break
                                        ;;
                                (-?*)
                                        i=$((i+1))
                                        ;;
                                (*)
                                        break
                                        ;;
                                esac
                        done
                        if ! $all && $delete || [ $i -gt ${WORDS[#]} ]; then
                                command -f completion/git::completeref --branches
                        else
                                command -f completion/git::completeref
                        fi
                        ;;
        esac

}


# vim: set ft=sh ts=8 sts=8 sw=8 et:
