# (C) 2011-2025 magicant

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

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

function completion/git::pull:arg {

        OPTIONS=( #>#
        "--no-rebase; don't rebase but merge"
        "q --quiet; don't report progress"
        "r:: --rebase::; rebase the current branch instead of merging"
        "v --verbose" # TODO description
        ) #<#
        if command -vf completion/git::fetch:getopt >/dev/null 2>&1 ||
                        . -AL completion/git-fetch; then
                command -f completion/git::fetch:getopt
        fi
        if command -vf completion/git::merge:getopt >/dev/null 2>&1 ||
                        . -AL completion/git-merge; then
                command -f completion/git::merge:getopt
        fi

        command -f completion//parseoptions
        case $ARGOPT in
                (-)
                        command -f completion//completeoptions
                        ;;
                (--negotiation-tip|--recurse-submodules|--refmap| \
                        --shallow-exclude|--upload-pack)
                        command -f completion/git::$ARGOPT:arg
                        ;;
#               (--depth)
#                       ;;
                (r|--rebase) #>>#
                        complete -P "$PREFIX" -D "don't rebase but merge" false
                        complete -P "$PREFIX" -D "rebase" true
                        complete -P "$PREFIX" -D "rebase recreating merge commits" merges
                        complete -P "$PREFIX" -D "rebase interactively" interactive
                        ;; #<<#
                ('')
                        command -f completion//getoperands
                        if [ ${WORDS[#]} -eq 0 ]; then
                                #TODO complete remote URI
                                command -f completion/git::completeremote
                        elif [ "${WORDS[-1]}" = tag ]; then
                                command -f completion/git::completeref --tags
                        else
                                typeset word="${TARGETWORD#"$PREFIX"}"
                                word=${word#+}
                                case $word in
                                (*:*) # complete local refs
                                        word=${word#*:}
                                        PREFIX=${TARGETWORD%"$word"}
                                        command -f completion/git::completeref
                                        ;;
                                (*) # complete remote refs
                                        PREFIX=${TARGETWORD%"$word"}
                                        command -f completion/git::completeremoteref "${WORDS[1]}"
                                        ;;
                                esac
                        fi
                        ;;
                (*)
                        command -f completion/git::merge:compopt
                        ;;
        esac

}


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