contrib / completion / git-completion.bashon commit Further merging down for 1.7.12.1 (cbd6b08)
   1#!bash
   2#
   3# bash/zsh completion support for core Git.
   4#
   5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
   6# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
   7# Distributed under the GNU General Public License, version 2.0.
   8#
   9# The contained completion routines provide support for completing:
  10#
  11#    *) local and remote branch names
  12#    *) local and remote tag names
  13#    *) .git/remotes file names
  14#    *) git 'subcommands'
  15#    *) tree paths within 'ref:path/to/file' expressions
  16#    *) common --long-options
  17#
  18# To use these routines:
  19#
  20#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  21#    2) Add the following line to your .bashrc/.zshrc:
  22#        source ~/.git-completion.sh
  23#    3) Consider changing your PS1 to also show the current branch,
  24#       see git-prompt.sh for details.
  25
  26if [[ -n ${ZSH_VERSION-} ]]; then
  27        autoload -U +X bashcompinit && bashcompinit
  28fi
  29
  30case "$COMP_WORDBREAKS" in
  31*:*) : great ;;
  32*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  33esac
  34
  35# __gitdir accepts 0 or 1 arguments (i.e., location)
  36# returns location of .git repo
  37__gitdir ()
  38{
  39        # Note: this function is duplicated in git-prompt.sh
  40        # When updating it, make sure you update the other one to match.
  41        if [ -z "${1-}" ]; then
  42                if [ -n "${__git_dir-}" ]; then
  43                        echo "$__git_dir"
  44                elif [ -n "${GIT_DIR-}" ]; then
  45                        test -d "${GIT_DIR-}" || return 1
  46                        echo "$GIT_DIR"
  47                elif [ -d .git ]; then
  48                        echo .git
  49                else
  50                        git rev-parse --git-dir 2>/dev/null
  51                fi
  52        elif [ -d "$1/.git" ]; then
  53                echo "$1/.git"
  54        else
  55                echo "$1"
  56        fi
  57}
  58
  59__gitcomp_1 ()
  60{
  61        local c IFS=$' \t\n'
  62        for c in $1; do
  63                c="$c$2"
  64                case $c in
  65                --*=*|*.) ;;
  66                *) c="$c " ;;
  67                esac
  68                printf '%s\n' "$c"
  69        done
  70}
  71
  72# The following function is based on code from:
  73#
  74#   bash_completion - programmable completion functions for bash 3.2+
  75#
  76#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
  77#             © 2009-2010, Bash Completion Maintainers
  78#                     <bash-completion-devel@lists.alioth.debian.org>
  79#
  80#   This program is free software; you can redistribute it and/or modify
  81#   it under the terms of the GNU General Public License as published by
  82#   the Free Software Foundation; either version 2, or (at your option)
  83#   any later version.
  84#
  85#   This program is distributed in the hope that it will be useful,
  86#   but WITHOUT ANY WARRANTY; without even the implied warranty of
  87#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  88#   GNU General Public License for more details.
  89#
  90#   You should have received a copy of the GNU General Public License
  91#   along with this program; if not, write to the Free Software Foundation,
  92#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  93#
  94#   The latest version of this software can be obtained here:
  95#
  96#   http://bash-completion.alioth.debian.org/
  97#
  98#   RELEASE: 2.x
  99
 100# This function can be used to access a tokenized list of words
 101# on the command line:
 102#
 103#       __git_reassemble_comp_words_by_ref '=:'
 104#       if test "${words_[cword_-1]}" = -w
 105#       then
 106#               ...
 107#       fi
 108#
 109# The argument should be a collection of characters from the list of
 110# word completion separators (COMP_WORDBREAKS) to treat as ordinary
 111# characters.
 112#
 113# This is roughly equivalent to going back in time and setting
 114# COMP_WORDBREAKS to exclude those characters.  The intent is to
 115# make option types like --date=<type> and <rev>:<path> easy to
 116# recognize by treating each shell word as a single token.
 117#
 118# It is best not to set COMP_WORDBREAKS directly because the value is
 119# shared with other completion scripts.  By the time the completion
 120# function gets called, COMP_WORDS has already been populated so local
 121# changes to COMP_WORDBREAKS have no effect.
 122#
 123# Output: words_, cword_, cur_.
 124
 125__git_reassemble_comp_words_by_ref()
 126{
 127        local exclude i j first
 128        # Which word separators to exclude?
 129        exclude="${1//[^$COMP_WORDBREAKS]}"
 130        cword_=$COMP_CWORD
 131        if [ -z "$exclude" ]; then
 132                words_=("${COMP_WORDS[@]}")
 133                return
 134        fi
 135        # List of word completion separators has shrunk;
 136        # re-assemble words to complete.
 137        for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
 138                # Append each nonempty word consisting of just
 139                # word separator characters to the current word.
 140                first=t
 141                while
 142                        [ $i -gt 0 ] &&
 143                        [ -n "${COMP_WORDS[$i]}" ] &&
 144                        # word consists of excluded word separators
 145                        [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
 146                do
 147                        # Attach to the previous token,
 148                        # unless the previous token is the command name.
 149                        if [ $j -ge 2 ] && [ -n "$first" ]; then
 150                                ((j--))
 151                        fi
 152                        first=
 153                        words_[$j]=${words_[j]}${COMP_WORDS[i]}
 154                        if [ $i = $COMP_CWORD ]; then
 155                                cword_=$j
 156                        fi
 157                        if (($i < ${#COMP_WORDS[@]} - 1)); then
 158                                ((i++))
 159                        else
 160                                # Done.
 161                                return
 162                        fi
 163                done
 164                words_[$j]=${words_[j]}${COMP_WORDS[i]}
 165                if [ $i = $COMP_CWORD ]; then
 166                        cword_=$j
 167                fi
 168        done
 169}
 170
 171if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
 172if [[ -z ${ZSH_VERSION:+set} ]]; then
 173_get_comp_words_by_ref ()
 174{
 175        local exclude cur_ words_ cword_
 176        if [ "$1" = "-n" ]; then
 177                exclude=$2
 178                shift 2
 179        fi
 180        __git_reassemble_comp_words_by_ref "$exclude"
 181        cur_=${words_[cword_]}
 182        while [ $# -gt 0 ]; do
 183                case "$1" in
 184                cur)
 185                        cur=$cur_
 186                        ;;
 187                prev)
 188                        prev=${words_[$cword_-1]}
 189                        ;;
 190                words)
 191                        words=("${words_[@]}")
 192                        ;;
 193                cword)
 194                        cword=$cword_
 195                        ;;
 196                esac
 197                shift
 198        done
 199}
 200else
 201_get_comp_words_by_ref ()
 202{
 203        while [ $# -gt 0 ]; do
 204                case "$1" in
 205                cur)
 206                        cur=${COMP_WORDS[COMP_CWORD]}
 207                        ;;
 208                prev)
 209                        prev=${COMP_WORDS[COMP_CWORD-1]}
 210                        ;;
 211                words)
 212                        words=("${COMP_WORDS[@]}")
 213                        ;;
 214                cword)
 215                        cword=$COMP_CWORD
 216                        ;;
 217                -n)
 218                        # assume COMP_WORDBREAKS is already set sanely
 219                        shift
 220                        ;;
 221                esac
 222                shift
 223        done
 224}
 225fi
 226fi
 227
 228# Generates completion reply with compgen, appending a space to possible
 229# completion words, if necessary.
 230# It accepts 1 to 4 arguments:
 231# 1: List of possible completion words.
 232# 2: A prefix to be added to each possible completion word (optional).
 233# 3: Generate possible completion matches for this word (optional).
 234# 4: A suffix to be appended to each possible completion word (optional).
 235__gitcomp ()
 236{
 237        local cur_="${3-$cur}"
 238
 239        case "$cur_" in
 240        --*=)
 241                COMPREPLY=()
 242                ;;
 243        *)
 244                local IFS=$'\n'
 245                COMPREPLY=($(compgen -P "${2-}" \
 246                        -W "$(__gitcomp_1 "${1-}" "${4-}")" \
 247                        -- "$cur_"))
 248                ;;
 249        esac
 250}
 251
 252# Generates completion reply with compgen from newline-separated possible
 253# completion words by appending a space to all of them.
 254# It accepts 1 to 4 arguments:
 255# 1: List of possible completion words, separated by a single newline.
 256# 2: A prefix to be added to each possible completion word (optional).
 257# 3: Generate possible completion matches for this word (optional).
 258# 4: A suffix to be appended to each possible completion word instead of
 259#    the default space (optional).  If specified but empty, nothing is
 260#    appended.
 261__gitcomp_nl ()
 262{
 263        local IFS=$'\n'
 264        COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
 265}
 266
 267__git_heads ()
 268{
 269        local dir="$(__gitdir)"
 270        if [ -d "$dir" ]; then
 271                git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
 272                        refs/heads
 273                return
 274        fi
 275}
 276
 277__git_tags ()
 278{
 279        local dir="$(__gitdir)"
 280        if [ -d "$dir" ]; then
 281                git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
 282                        refs/tags
 283                return
 284        fi
 285}
 286
 287# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
 288# presence of 2nd argument means use the guess heuristic employed
 289# by checkout for tracking branches
 290__git_refs ()
 291{
 292        local i hash dir="$(__gitdir "${1-}")" track="${2-}"
 293        local format refs
 294        if [ -d "$dir" ]; then
 295                case "$cur" in
 296                refs|refs/*)
 297                        format="refname"
 298                        refs="${cur%/*}"
 299                        track=""
 300                        ;;
 301                *)
 302                        for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
 303                                if [ -e "$dir/$i" ]; then echo $i; fi
 304                        done
 305                        format="refname:short"
 306                        refs="refs/tags refs/heads refs/remotes"
 307                        ;;
 308                esac
 309                git --git-dir="$dir" for-each-ref --format="%($format)" \
 310                        $refs
 311                if [ -n "$track" ]; then
 312                        # employ the heuristic used by git checkout
 313                        # Try to find a remote branch that matches the completion word
 314                        # but only output if the branch name is unique
 315                        local ref entry
 316                        git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
 317                                "refs/remotes/" | \
 318                        while read -r entry; do
 319                                eval "$entry"
 320                                ref="${ref#*/}"
 321                                if [[ "$ref" == "$cur"* ]]; then
 322                                        echo "$ref"
 323                                fi
 324                        done | uniq -u
 325                fi
 326                return
 327        fi
 328        case "$cur" in
 329        refs|refs/*)
 330                git ls-remote "$dir" "$cur*" 2>/dev/null | \
 331                while read -r hash i; do
 332                        case "$i" in
 333                        *^{}) ;;
 334                        *) echo "$i" ;;
 335                        esac
 336                done
 337                ;;
 338        *)
 339                git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
 340                while read -r hash i; do
 341                        case "$i" in
 342                        *^{}) ;;
 343                        refs/*) echo "${i#refs/*/}" ;;
 344                        *) echo "$i" ;;
 345                        esac
 346                done
 347                ;;
 348        esac
 349}
 350
 351# __git_refs2 requires 1 argument (to pass to __git_refs)
 352__git_refs2 ()
 353{
 354        local i
 355        for i in $(__git_refs "$1"); do
 356                echo "$i:$i"
 357        done
 358}
 359
 360# __git_refs_remotes requires 1 argument (to pass to ls-remote)
 361__git_refs_remotes ()
 362{
 363        local i hash
 364        git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
 365        while read -r hash i; do
 366                echo "$i:refs/remotes/$1/${i#refs/heads/}"
 367        done
 368}
 369
 370__git_remotes ()
 371{
 372        local i IFS=$'\n' d="$(__gitdir)"
 373        test -d "$d/remotes" && ls -1 "$d/remotes"
 374        for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
 375                i="${i#remote.}"
 376                echo "${i/.url*/}"
 377        done
 378}
 379
 380__git_list_merge_strategies ()
 381{
 382        git merge -s help 2>&1 |
 383        sed -n -e '/[Aa]vailable strategies are: /,/^$/{
 384                s/\.$//
 385                s/.*://
 386                s/^[    ]*//
 387                s/[     ]*$//
 388                p
 389        }'
 390}
 391
 392__git_merge_strategies=
 393# 'git merge -s help' (and thus detection of the merge strategy
 394# list) fails, unfortunately, if run outside of any git working
 395# tree.  __git_merge_strategies is set to the empty string in
 396# that case, and the detection will be repeated the next time it
 397# is needed.
 398__git_compute_merge_strategies ()
 399{
 400        test -n "$__git_merge_strategies" ||
 401        __git_merge_strategies=$(__git_list_merge_strategies)
 402}
 403
 404__git_complete_revlist_file ()
 405{
 406        local pfx ls ref cur_="$cur"
 407        case "$cur_" in
 408        *..?*:*)
 409                return
 410                ;;
 411        ?*:*)
 412                ref="${cur_%%:*}"
 413                cur_="${cur_#*:}"
 414                case "$cur_" in
 415                ?*/*)
 416                        pfx="${cur_%/*}"
 417                        cur_="${cur_##*/}"
 418                        ls="$ref:$pfx"
 419                        pfx="$pfx/"
 420                        ;;
 421                *)
 422                        ls="$ref"
 423                        ;;
 424                esac
 425
 426                case "$COMP_WORDBREAKS" in
 427                *:*) : great ;;
 428                *)   pfx="$ref:$pfx" ;;
 429                esac
 430
 431                __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 432                                | sed '/^100... blob /{
 433                                           s,^.*        ,,
 434                                           s,$, ,
 435                                       }
 436                                       /^120000 blob /{
 437                                           s,^.*        ,,
 438                                           s,$, ,
 439                                       }
 440                                       /^040000 tree /{
 441                                           s,^.*        ,,
 442                                           s,$,/,
 443                                       }
 444                                       s/^.*    //')" \
 445                        "$pfx" "$cur_" ""
 446                ;;
 447        *...*)
 448                pfx="${cur_%...*}..."
 449                cur_="${cur_#*...}"
 450                __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 451                ;;
 452        *..*)
 453                pfx="${cur_%..*}.."
 454                cur_="${cur_#*..}"
 455                __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 456                ;;
 457        *)
 458                __gitcomp_nl "$(__git_refs)"
 459                ;;
 460        esac
 461}
 462
 463
 464__git_complete_file ()
 465{
 466        __git_complete_revlist_file
 467}
 468
 469__git_complete_revlist ()
 470{
 471        __git_complete_revlist_file
 472}
 473
 474__git_complete_remote_or_refspec ()
 475{
 476        local cur_="$cur" cmd="${words[1]}"
 477        local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
 478        if [ "$cmd" = "remote" ]; then
 479                ((c++))
 480        fi
 481        while [ $c -lt $cword ]; do
 482                i="${words[c]}"
 483                case "$i" in
 484                --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
 485                --all)
 486                        case "$cmd" in
 487                        push) no_complete_refspec=1 ;;
 488                        fetch)
 489                                COMPREPLY=()
 490                                return
 491                                ;;
 492                        *) ;;
 493                        esac
 494                        ;;
 495                -*) ;;
 496                *) remote="$i"; break ;;
 497                esac
 498                ((c++))
 499        done
 500        if [ -z "$remote" ]; then
 501                __gitcomp_nl "$(__git_remotes)"
 502                return
 503        fi
 504        if [ $no_complete_refspec = 1 ]; then
 505                COMPREPLY=()
 506                return
 507        fi
 508        [ "$remote" = "." ] && remote=
 509        case "$cur_" in
 510        *:*)
 511                case "$COMP_WORDBREAKS" in
 512                *:*) : great ;;
 513                *)   pfx="${cur_%%:*}:" ;;
 514                esac
 515                cur_="${cur_#*:}"
 516                lhs=0
 517                ;;
 518        +*)
 519                pfx="+"
 520                cur_="${cur_#+}"
 521                ;;
 522        esac
 523        case "$cmd" in
 524        fetch)
 525                if [ $lhs = 1 ]; then
 526                        __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
 527                else
 528                        __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 529                fi
 530                ;;
 531        pull|remote)
 532                if [ $lhs = 1 ]; then
 533                        __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
 534                else
 535                        __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 536                fi
 537                ;;
 538        push)
 539                if [ $lhs = 1 ]; then
 540                        __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
 541                else
 542                        __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
 543                fi
 544                ;;
 545        esac
 546}
 547
 548__git_complete_strategy ()
 549{
 550        __git_compute_merge_strategies
 551        case "$prev" in
 552        -s|--strategy)
 553                __gitcomp "$__git_merge_strategies"
 554                return 0
 555        esac
 556        case "$cur" in
 557        --strategy=*)
 558                __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
 559                return 0
 560                ;;
 561        esac
 562        return 1
 563}
 564
 565__git_list_all_commands ()
 566{
 567        local i IFS=" "$'\n'
 568        for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
 569        do
 570                case $i in
 571                *--*)             : helper pattern;;
 572                *) echo $i;;
 573                esac
 574        done
 575}
 576
 577__git_all_commands=
 578__git_compute_all_commands ()
 579{
 580        test -n "$__git_all_commands" ||
 581        __git_all_commands=$(__git_list_all_commands)
 582}
 583
 584__git_list_porcelain_commands ()
 585{
 586        local i IFS=" "$'\n'
 587        __git_compute_all_commands
 588        for i in "help" $__git_all_commands
 589        do
 590                case $i in
 591                *--*)             : helper pattern;;
 592                applymbox)        : ask gittus;;
 593                applypatch)       : ask gittus;;
 594                archimport)       : import;;
 595                cat-file)         : plumbing;;
 596                check-attr)       : plumbing;;
 597                check-ref-format) : plumbing;;
 598                checkout-index)   : plumbing;;
 599                commit-tree)      : plumbing;;
 600                count-objects)    : infrequent;;
 601                credential-cache) : credentials helper;;
 602                credential-store) : credentials helper;;
 603                cvsexportcommit)  : export;;
 604                cvsimport)        : import;;
 605                cvsserver)        : daemon;;
 606                daemon)           : daemon;;
 607                diff-files)       : plumbing;;
 608                diff-index)       : plumbing;;
 609                diff-tree)        : plumbing;;
 610                fast-import)      : import;;
 611                fast-export)      : export;;
 612                fsck-objects)     : plumbing;;
 613                fetch-pack)       : plumbing;;
 614                fmt-merge-msg)    : plumbing;;
 615                for-each-ref)     : plumbing;;
 616                hash-object)      : plumbing;;
 617                http-*)           : transport;;
 618                index-pack)       : plumbing;;
 619                init-db)          : deprecated;;
 620                local-fetch)      : plumbing;;
 621                lost-found)       : infrequent;;
 622                ls-files)         : plumbing;;
 623                ls-remote)        : plumbing;;
 624                ls-tree)          : plumbing;;
 625                mailinfo)         : plumbing;;
 626                mailsplit)        : plumbing;;
 627                merge-*)          : plumbing;;
 628                mktree)           : plumbing;;
 629                mktag)            : plumbing;;
 630                pack-objects)     : plumbing;;
 631                pack-redundant)   : plumbing;;
 632                pack-refs)        : plumbing;;
 633                parse-remote)     : plumbing;;
 634                patch-id)         : plumbing;;
 635                peek-remote)      : plumbing;;
 636                prune)            : plumbing;;
 637                prune-packed)     : plumbing;;
 638                quiltimport)      : import;;
 639                read-tree)        : plumbing;;
 640                receive-pack)     : plumbing;;
 641                remote-*)         : transport;;
 642                repo-config)      : deprecated;;
 643                rerere)           : plumbing;;
 644                rev-list)         : plumbing;;
 645                rev-parse)        : plumbing;;
 646                runstatus)        : plumbing;;
 647                sh-setup)         : internal;;
 648                shell)            : daemon;;
 649                show-ref)         : plumbing;;
 650                send-pack)        : plumbing;;
 651                show-index)       : plumbing;;
 652                ssh-*)            : transport;;
 653                stripspace)       : plumbing;;
 654                symbolic-ref)     : plumbing;;
 655                tar-tree)         : deprecated;;
 656                unpack-file)      : plumbing;;
 657                unpack-objects)   : plumbing;;
 658                update-index)     : plumbing;;
 659                update-ref)       : plumbing;;
 660                update-server-info) : daemon;;
 661                upload-archive)   : plumbing;;
 662                upload-pack)      : plumbing;;
 663                write-tree)       : plumbing;;
 664                var)              : infrequent;;
 665                verify-pack)      : infrequent;;
 666                verify-tag)       : plumbing;;
 667                *) echo $i;;
 668                esac
 669        done
 670}
 671
 672__git_porcelain_commands=
 673__git_compute_porcelain_commands ()
 674{
 675        __git_compute_all_commands
 676        test -n "$__git_porcelain_commands" ||
 677        __git_porcelain_commands=$(__git_list_porcelain_commands)
 678}
 679
 680__git_pretty_aliases ()
 681{
 682        local i IFS=$'\n'
 683        for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
 684                case "$i" in
 685                pretty.*)
 686                        i="${i#pretty.}"
 687                        echo "${i/ */}"
 688                        ;;
 689                esac
 690        done
 691}
 692
 693__git_aliases ()
 694{
 695        local i IFS=$'\n'
 696        for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
 697                case "$i" in
 698                alias.*)
 699                        i="${i#alias.}"
 700                        echo "${i/ */}"
 701                        ;;
 702                esac
 703        done
 704}
 705
 706# __git_aliased_command requires 1 argument
 707__git_aliased_command ()
 708{
 709        local word cmdline=$(git --git-dir="$(__gitdir)" \
 710                config --get "alias.$1")
 711        for word in $cmdline; do
 712                case "$word" in
 713                \!gitk|gitk)
 714                        echo "gitk"
 715                        return
 716                        ;;
 717                \!*)    : shell command alias ;;
 718                -*)     : option ;;
 719                *=*)    : setting env ;;
 720                git)    : git itself ;;
 721                *)
 722                        echo "$word"
 723                        return
 724                esac
 725        done
 726}
 727
 728# __git_find_on_cmdline requires 1 argument
 729__git_find_on_cmdline ()
 730{
 731        local word subcommand c=1
 732        while [ $c -lt $cword ]; do
 733                word="${words[c]}"
 734                for subcommand in $1; do
 735                        if [ "$subcommand" = "$word" ]; then
 736                                echo "$subcommand"
 737                                return
 738                        fi
 739                done
 740                ((c++))
 741        done
 742}
 743
 744__git_has_doubledash ()
 745{
 746        local c=1
 747        while [ $c -lt $cword ]; do
 748                if [ "--" = "${words[c]}" ]; then
 749                        return 0
 750                fi
 751                ((c++))
 752        done
 753        return 1
 754}
 755
 756__git_whitespacelist="nowarn warn error error-all fix"
 757
 758_git_am ()
 759{
 760        local dir="$(__gitdir)"
 761        if [ -d "$dir"/rebase-apply ]; then
 762                __gitcomp "--skip --continue --resolved --abort"
 763                return
 764        fi
 765        case "$cur" in
 766        --whitespace=*)
 767                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 768                return
 769                ;;
 770        --*)
 771                __gitcomp "
 772                        --3way --committer-date-is-author-date --ignore-date
 773                        --ignore-whitespace --ignore-space-change
 774                        --interactive --keep --no-utf8 --signoff --utf8
 775                        --whitespace= --scissors
 776                        "
 777                return
 778        esac
 779        COMPREPLY=()
 780}
 781
 782_git_apply ()
 783{
 784        case "$cur" in
 785        --whitespace=*)
 786                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 787                return
 788                ;;
 789        --*)
 790                __gitcomp "
 791                        --stat --numstat --summary --check --index
 792                        --cached --index-info --reverse --reject --unidiff-zero
 793                        --apply --no-add --exclude=
 794                        --ignore-whitespace --ignore-space-change
 795                        --whitespace= --inaccurate-eof --verbose
 796                        "
 797                return
 798        esac
 799        COMPREPLY=()
 800}
 801
 802_git_add ()
 803{
 804        __git_has_doubledash && return
 805
 806        case "$cur" in
 807        --*)
 808                __gitcomp "
 809                        --interactive --refresh --patch --update --dry-run
 810                        --ignore-errors --intent-to-add
 811                        "
 812                return
 813        esac
 814        COMPREPLY=()
 815}
 816
 817_git_archive ()
 818{
 819        case "$cur" in
 820        --format=*)
 821                __gitcomp "$(git archive --list)" "" "${cur##--format=}"
 822                return
 823                ;;
 824        --remote=*)
 825                __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
 826                return
 827                ;;
 828        --*)
 829                __gitcomp "
 830                        --format= --list --verbose
 831                        --prefix= --remote= --exec=
 832                        "
 833                return
 834                ;;
 835        esac
 836        __git_complete_file
 837}
 838
 839_git_bisect ()
 840{
 841        __git_has_doubledash && return
 842
 843        local subcommands="start bad good skip reset visualize replay log run"
 844        local subcommand="$(__git_find_on_cmdline "$subcommands")"
 845        if [ -z "$subcommand" ]; then
 846                if [ -f "$(__gitdir)"/BISECT_START ]; then
 847                        __gitcomp "$subcommands"
 848                else
 849                        __gitcomp "replay start"
 850                fi
 851                return
 852        fi
 853
 854        case "$subcommand" in
 855        bad|good|reset|skip|start)
 856                __gitcomp_nl "$(__git_refs)"
 857                ;;
 858        *)
 859                COMPREPLY=()
 860                ;;
 861        esac
 862}
 863
 864_git_branch ()
 865{
 866        local i c=1 only_local_ref="n" has_r="n"
 867
 868        while [ $c -lt $cword ]; do
 869                i="${words[c]}"
 870                case "$i" in
 871                -d|-m)  only_local_ref="y" ;;
 872                -r)     has_r="y" ;;
 873                esac
 874                ((c++))
 875        done
 876
 877        case "$cur" in
 878        --*)
 879                __gitcomp "
 880                        --color --no-color --verbose --abbrev= --no-abbrev
 881                        --track --no-track --contains --merged --no-merged
 882                        --set-upstream --edit-description --list
 883                        "
 884                ;;
 885        *)
 886                if [ $only_local_ref = "y" -a $has_r = "n" ]; then
 887                        __gitcomp_nl "$(__git_heads)"
 888                else
 889                        __gitcomp_nl "$(__git_refs)"
 890                fi
 891                ;;
 892        esac
 893}
 894
 895_git_bundle ()
 896{
 897        local cmd="${words[2]}"
 898        case "$cword" in
 899        2)
 900                __gitcomp "create list-heads verify unbundle"
 901                ;;
 902        3)
 903                # looking for a file
 904                ;;
 905        *)
 906                case "$cmd" in
 907                        create)
 908                                __git_complete_revlist
 909                        ;;
 910                esac
 911                ;;
 912        esac
 913}
 914
 915_git_checkout ()
 916{
 917        __git_has_doubledash && return
 918
 919        case "$cur" in
 920        --conflict=*)
 921                __gitcomp "diff3 merge" "" "${cur##--conflict=}"
 922                ;;
 923        --*)
 924                __gitcomp "
 925                        --quiet --ours --theirs --track --no-track --merge
 926                        --conflict= --orphan --patch
 927                        "
 928                ;;
 929        *)
 930                # check if --track, --no-track, or --no-guess was specified
 931                # if so, disable DWIM mode
 932                local flags="--track --no-track --no-guess" track=1
 933                if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
 934                        track=''
 935                fi
 936                __gitcomp_nl "$(__git_refs '' $track)"
 937                ;;
 938        esac
 939}
 940
 941_git_cherry ()
 942{
 943        __gitcomp "$(__git_refs)"
 944}
 945
 946_git_cherry_pick ()
 947{
 948        case "$cur" in
 949        --*)
 950                __gitcomp "--edit --no-commit"
 951                ;;
 952        *)
 953                __gitcomp_nl "$(__git_refs)"
 954                ;;
 955        esac
 956}
 957
 958_git_clean ()
 959{
 960        __git_has_doubledash && return
 961
 962        case "$cur" in
 963        --*)
 964                __gitcomp "--dry-run --quiet"
 965                return
 966                ;;
 967        esac
 968        COMPREPLY=()
 969}
 970
 971_git_clone ()
 972{
 973        case "$cur" in
 974        --*)
 975                __gitcomp "
 976                        --local
 977                        --no-hardlinks
 978                        --shared
 979                        --reference
 980                        --quiet
 981                        --no-checkout
 982                        --bare
 983                        --mirror
 984                        --origin
 985                        --upload-pack
 986                        --template=
 987                        --depth
 988                        "
 989                return
 990                ;;
 991        esac
 992        COMPREPLY=()
 993}
 994
 995_git_commit ()
 996{
 997        __git_has_doubledash && return
 998
 999        case "$cur" in
1000        --cleanup=*)
1001                __gitcomp "default strip verbatim whitespace
1002                        " "" "${cur##--cleanup=}"
1003                return
1004                ;;
1005        --reuse-message=*|--reedit-message=*|\
1006        --fixup=*|--squash=*)
1007                __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1008                return
1009                ;;
1010        --untracked-files=*)
1011                __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1012                return
1013                ;;
1014        --*)
1015                __gitcomp "
1016                        --all --author= --signoff --verify --no-verify
1017                        --edit --amend --include --only --interactive
1018                        --dry-run --reuse-message= --reedit-message=
1019                        --reset-author --file= --message= --template=
1020                        --cleanup= --untracked-files --untracked-files=
1021                        --verbose --quiet --fixup= --squash=
1022                        "
1023                return
1024        esac
1025        COMPREPLY=()
1026}
1027
1028_git_describe ()
1029{
1030        case "$cur" in
1031        --*)
1032                __gitcomp "
1033                        --all --tags --contains --abbrev= --candidates=
1034                        --exact-match --debug --long --match --always
1035                        "
1036                return
1037        esac
1038        __gitcomp_nl "$(__git_refs)"
1039}
1040
1041__git_diff_common_options="--stat --numstat --shortstat --summary
1042                        --patch-with-stat --name-only --name-status --color
1043                        --no-color --color-words --no-renames --check
1044                        --full-index --binary --abbrev --diff-filter=
1045                        --find-copies-harder
1046                        --text --ignore-space-at-eol --ignore-space-change
1047                        --ignore-all-space --exit-code --quiet --ext-diff
1048                        --no-ext-diff
1049                        --no-prefix --src-prefix= --dst-prefix=
1050                        --inter-hunk-context=
1051                        --patience
1052                        --raw
1053                        --dirstat --dirstat= --dirstat-by-file
1054                        --dirstat-by-file= --cumulative
1055"
1056
1057_git_diff ()
1058{
1059        __git_has_doubledash && return
1060
1061        case "$cur" in
1062        --*)
1063                __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1064                        --base --ours --theirs --no-index
1065                        $__git_diff_common_options
1066                        "
1067                return
1068                ;;
1069        esac
1070        __git_complete_revlist_file
1071}
1072
1073__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1074                        tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1075"
1076
1077_git_difftool ()
1078{
1079        __git_has_doubledash && return
1080
1081        case "$cur" in
1082        --tool=*)
1083                __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1084                return
1085                ;;
1086        --*)
1087                __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1088                        --base --ours --theirs
1089                        --no-renames --diff-filter= --find-copies-harder
1090                        --relative --ignore-submodules
1091                        --tool="
1092                return
1093                ;;
1094        esac
1095        __git_complete_file
1096}
1097
1098__git_fetch_options="
1099        --quiet --verbose --append --upload-pack --force --keep --depth=
1100        --tags --no-tags --all --prune --dry-run
1101"
1102
1103_git_fetch ()
1104{
1105        case "$cur" in
1106        --*)
1107                __gitcomp "$__git_fetch_options"
1108                return
1109                ;;
1110        esac
1111        __git_complete_remote_or_refspec
1112}
1113
1114_git_format_patch ()
1115{
1116        case "$cur" in
1117        --thread=*)
1118                __gitcomp "
1119                        deep shallow
1120                        " "" "${cur##--thread=}"
1121                return
1122                ;;
1123        --*)
1124                __gitcomp "
1125                        --stdout --attach --no-attach --thread --thread=
1126                        --output-directory
1127                        --numbered --start-number
1128                        --numbered-files
1129                        --keep-subject
1130                        --signoff --signature --no-signature
1131                        --in-reply-to= --cc=
1132                        --full-index --binary
1133                        --not --all
1134                        --cover-letter
1135                        --no-prefix --src-prefix= --dst-prefix=
1136                        --inline --suffix= --ignore-if-in-upstream
1137                        --subject-prefix=
1138                        "
1139                return
1140                ;;
1141        esac
1142        __git_complete_revlist
1143}
1144
1145_git_fsck ()
1146{
1147        case "$cur" in
1148        --*)
1149                __gitcomp "
1150                        --tags --root --unreachable --cache --no-reflogs --full
1151                        --strict --verbose --lost-found
1152                        "
1153                return
1154                ;;
1155        esac
1156        COMPREPLY=()
1157}
1158
1159_git_gc ()
1160{
1161        case "$cur" in
1162        --*)
1163                __gitcomp "--prune --aggressive"
1164                return
1165                ;;
1166        esac
1167        COMPREPLY=()
1168}
1169
1170_git_gitk ()
1171{
1172        _gitk
1173}
1174
1175__git_match_ctag() {
1176        awk "/^${1////\\/}/ { print \$1 }" "$2"
1177}
1178
1179_git_grep ()
1180{
1181        __git_has_doubledash && return
1182
1183        case "$cur" in
1184        --*)
1185                __gitcomp "
1186                        --cached
1187                        --text --ignore-case --word-regexp --invert-match
1188                        --full-name --line-number
1189                        --extended-regexp --basic-regexp --fixed-strings
1190                        --perl-regexp
1191                        --files-with-matches --name-only
1192                        --files-without-match
1193                        --max-depth
1194                        --count
1195                        --and --or --not --all-match
1196                        "
1197                return
1198                ;;
1199        esac
1200
1201        case "$cword,$prev" in
1202        2,*|*,-*)
1203                if test -r tags; then
1204                        __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1205                        return
1206                fi
1207                ;;
1208        esac
1209
1210        __gitcomp_nl "$(__git_refs)"
1211}
1212
1213_git_help ()
1214{
1215        case "$cur" in
1216        --*)
1217                __gitcomp "--all --info --man --web"
1218                return
1219                ;;
1220        esac
1221        __git_compute_all_commands
1222        __gitcomp "$__git_all_commands $(__git_aliases)
1223                attributes cli core-tutorial cvs-migration
1224                diffcore gitk glossary hooks ignore modules
1225                namespaces repository-layout tutorial tutorial-2
1226                workflows
1227                "
1228}
1229
1230_git_init ()
1231{
1232        case "$cur" in
1233        --shared=*)
1234                __gitcomp "
1235                        false true umask group all world everybody
1236                        " "" "${cur##--shared=}"
1237                return
1238                ;;
1239        --*)
1240                __gitcomp "--quiet --bare --template= --shared --shared="
1241                return
1242                ;;
1243        esac
1244        COMPREPLY=()
1245}
1246
1247_git_ls_files ()
1248{
1249        __git_has_doubledash && return
1250
1251        case "$cur" in
1252        --*)
1253                __gitcomp "--cached --deleted --modified --others --ignored
1254                        --stage --directory --no-empty-directory --unmerged
1255                        --killed --exclude= --exclude-from=
1256                        --exclude-per-directory= --exclude-standard
1257                        --error-unmatch --with-tree= --full-name
1258                        --abbrev --ignored --exclude-per-directory
1259                        "
1260                return
1261                ;;
1262        esac
1263        COMPREPLY=()
1264}
1265
1266_git_ls_remote ()
1267{
1268        __gitcomp_nl "$(__git_remotes)"
1269}
1270
1271_git_ls_tree ()
1272{
1273        __git_complete_file
1274}
1275
1276# Options that go well for log, shortlog and gitk
1277__git_log_common_options="
1278        --not --all
1279        --branches --tags --remotes
1280        --first-parent --merges --no-merges
1281        --max-count=
1282        --max-age= --since= --after=
1283        --min-age= --until= --before=
1284        --min-parents= --max-parents=
1285        --no-min-parents --no-max-parents
1286"
1287# Options that go well for log and gitk (not shortlog)
1288__git_log_gitk_options="
1289        --dense --sparse --full-history
1290        --simplify-merges --simplify-by-decoration
1291        --left-right --notes --no-notes
1292"
1293# Options that go well for log and shortlog (not gitk)
1294__git_log_shortlog_options="
1295        --author= --committer= --grep=
1296        --all-match
1297"
1298
1299__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1300__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1301
1302_git_log ()
1303{
1304        __git_has_doubledash && return
1305
1306        local g="$(git rev-parse --git-dir 2>/dev/null)"
1307        local merge=""
1308        if [ -f "$g/MERGE_HEAD" ]; then
1309                merge="--merge"
1310        fi
1311        case "$cur" in
1312        --pretty=*|--format=*)
1313                __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1314                        " "" "${cur#*=}"
1315                return
1316                ;;
1317        --date=*)
1318                __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1319                return
1320                ;;
1321        --decorate=*)
1322                __gitcomp "long short" "" "${cur##--decorate=}"
1323                return
1324                ;;
1325        --*)
1326                __gitcomp "
1327                        $__git_log_common_options
1328                        $__git_log_shortlog_options
1329                        $__git_log_gitk_options
1330                        --root --topo-order --date-order --reverse
1331                        --follow --full-diff
1332                        --abbrev-commit --abbrev=
1333                        --relative-date --date=
1334                        --pretty= --format= --oneline
1335                        --cherry-pick
1336                        --graph
1337                        --decorate --decorate=
1338                        --walk-reflogs
1339                        --parents --children
1340                        $merge
1341                        $__git_diff_common_options
1342                        --pickaxe-all --pickaxe-regex
1343                        "
1344                return
1345                ;;
1346        esac
1347        __git_complete_revlist
1348}
1349
1350__git_merge_options="
1351        --no-commit --no-stat --log --no-log --squash --strategy
1352        --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1353"
1354
1355_git_merge ()
1356{
1357        __git_complete_strategy && return
1358
1359        case "$cur" in
1360        --*)
1361                __gitcomp "$__git_merge_options"
1362                return
1363        esac
1364        __gitcomp_nl "$(__git_refs)"
1365}
1366
1367_git_mergetool ()
1368{
1369        case "$cur" in
1370        --tool=*)
1371                __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1372                return
1373                ;;
1374        --*)
1375                __gitcomp "--tool="
1376                return
1377                ;;
1378        esac
1379        COMPREPLY=()
1380}
1381
1382_git_merge_base ()
1383{
1384        __gitcomp_nl "$(__git_refs)"
1385}
1386
1387_git_mv ()
1388{
1389        case "$cur" in
1390        --*)
1391                __gitcomp "--dry-run"
1392                return
1393                ;;
1394        esac
1395        COMPREPLY=()
1396}
1397
1398_git_name_rev ()
1399{
1400        __gitcomp "--tags --all --stdin"
1401}
1402
1403_git_notes ()
1404{
1405        local subcommands='add append copy edit list prune remove show'
1406        local subcommand="$(__git_find_on_cmdline "$subcommands")"
1407
1408        case "$subcommand,$cur" in
1409        ,--*)
1410                __gitcomp '--ref'
1411                ;;
1412        ,*)
1413                case "$prev" in
1414                --ref)
1415                        __gitcomp_nl "$(__git_refs)"
1416                        ;;
1417                *)
1418                        __gitcomp "$subcommands --ref"
1419                        ;;
1420                esac
1421                ;;
1422        add,--reuse-message=*|append,--reuse-message=*|\
1423        add,--reedit-message=*|append,--reedit-message=*)
1424                __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1425                ;;
1426        add,--*|append,--*)
1427                __gitcomp '--file= --message= --reedit-message=
1428                                --reuse-message='
1429                ;;
1430        copy,--*)
1431                __gitcomp '--stdin'
1432                ;;
1433        prune,--*)
1434                __gitcomp '--dry-run --verbose'
1435                ;;
1436        prune,*)
1437                ;;
1438        *)
1439                case "$prev" in
1440                -m|-F)
1441                        ;;
1442                *)
1443                        __gitcomp_nl "$(__git_refs)"
1444                        ;;
1445                esac
1446                ;;
1447        esac
1448}
1449
1450_git_pull ()
1451{
1452        __git_complete_strategy && return
1453
1454        case "$cur" in
1455        --*)
1456                __gitcomp "
1457                        --rebase --no-rebase
1458                        $__git_merge_options
1459                        $__git_fetch_options
1460                "
1461                return
1462                ;;
1463        esac
1464        __git_complete_remote_or_refspec
1465}
1466
1467_git_push ()
1468{
1469        case "$prev" in
1470        --repo)
1471                __gitcomp_nl "$(__git_remotes)"
1472                return
1473        esac
1474        case "$cur" in
1475        --repo=*)
1476                __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1477                return
1478                ;;
1479        --*)
1480                __gitcomp "
1481                        --all --mirror --tags --dry-run --force --verbose
1482                        --receive-pack= --repo= --set-upstream
1483                "
1484                return
1485                ;;
1486        esac
1487        __git_complete_remote_or_refspec
1488}
1489
1490_git_rebase ()
1491{
1492        local dir="$(__gitdir)"
1493        if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1494                __gitcomp "--continue --skip --abort"
1495                return
1496        fi
1497        __git_complete_strategy && return
1498        case "$cur" in
1499        --whitespace=*)
1500                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1501                return
1502                ;;
1503        --*)
1504                __gitcomp "
1505                        --onto --merge --strategy --interactive
1506                        --preserve-merges --stat --no-stat
1507                        --committer-date-is-author-date --ignore-date
1508                        --ignore-whitespace --whitespace=
1509                        --autosquash
1510                        "
1511
1512                return
1513        esac
1514        __gitcomp_nl "$(__git_refs)"
1515}
1516
1517_git_reflog ()
1518{
1519        local subcommands="show delete expire"
1520        local subcommand="$(__git_find_on_cmdline "$subcommands")"
1521
1522        if [ -z "$subcommand" ]; then
1523                __gitcomp "$subcommands"
1524        else
1525                __gitcomp_nl "$(__git_refs)"
1526        fi
1527}
1528
1529__git_send_email_confirm_options="always never auto cc compose"
1530__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1531
1532_git_send_email ()
1533{
1534        case "$cur" in
1535        --confirm=*)
1536                __gitcomp "
1537                        $__git_send_email_confirm_options
1538                        " "" "${cur##--confirm=}"
1539                return
1540                ;;
1541        --suppress-cc=*)
1542                __gitcomp "
1543                        $__git_send_email_suppresscc_options
1544                        " "" "${cur##--suppress-cc=}"
1545
1546                return
1547                ;;
1548        --smtp-encryption=*)
1549                __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1550                return
1551                ;;
1552        --*)
1553                __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1554                        --compose --confirm= --dry-run --envelope-sender
1555                        --from --identity
1556                        --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1557                        --no-suppress-from --no-thread --quiet
1558                        --signed-off-by-cc --smtp-pass --smtp-server
1559                        --smtp-server-port --smtp-encryption= --smtp-user
1560                        --subject --suppress-cc= --suppress-from --thread --to
1561                        --validate --no-validate"
1562                return
1563                ;;
1564        esac
1565        COMPREPLY=()
1566}
1567
1568_git_stage ()
1569{
1570        _git_add
1571}
1572
1573__git_config_get_set_variables ()
1574{
1575        local prevword word config_file= c=$cword
1576        while [ $c -gt 1 ]; do
1577                word="${words[c]}"
1578                case "$word" in
1579                --global|--system|--file=*)
1580                        config_file="$word"
1581                        break
1582                        ;;
1583                -f|--file)
1584                        config_file="$word $prevword"
1585                        break
1586                        ;;
1587                esac
1588                prevword=$word
1589                c=$((--c))
1590        done
1591
1592        git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1593        while read -r line
1594        do
1595                case "$line" in
1596                *.*=*)
1597                        echo "${line/=*/}"
1598                        ;;
1599                esac
1600        done
1601}
1602
1603_git_config ()
1604{
1605        case "$prev" in
1606        branch.*.remote)
1607                __gitcomp_nl "$(__git_remotes)"
1608                return
1609                ;;
1610        branch.*.merge)
1611                __gitcomp_nl "$(__git_refs)"
1612                return
1613                ;;
1614        remote.*.fetch)
1615                local remote="${prev#remote.}"
1616                remote="${remote%.fetch}"
1617                if [ -z "$cur" ]; then
1618                        COMPREPLY=("refs/heads/")
1619                        return
1620                fi
1621                __gitcomp_nl "$(__git_refs_remotes "$remote")"
1622                return
1623                ;;
1624        remote.*.push)
1625                local remote="${prev#remote.}"
1626                remote="${remote%.push}"
1627                __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1628                        for-each-ref --format='%(refname):%(refname)' \
1629                        refs/heads)"
1630                return
1631                ;;
1632        pull.twohead|pull.octopus)
1633                __git_compute_merge_strategies
1634                __gitcomp "$__git_merge_strategies"
1635                return
1636                ;;
1637        color.branch|color.diff|color.interactive|\
1638        color.showbranch|color.status|color.ui)
1639                __gitcomp "always never auto"
1640                return
1641                ;;
1642        color.pager)
1643                __gitcomp "false true"
1644                return
1645                ;;
1646        color.*.*)
1647                __gitcomp "
1648                        normal black red green yellow blue magenta cyan white
1649                        bold dim ul blink reverse
1650                        "
1651                return
1652                ;;
1653        help.format)
1654                __gitcomp "man info web html"
1655                return
1656                ;;
1657        log.date)
1658                __gitcomp "$__git_log_date_formats"
1659                return
1660                ;;
1661        sendemail.aliasesfiletype)
1662                __gitcomp "mutt mailrc pine elm gnus"
1663                return
1664                ;;
1665        sendemail.confirm)
1666                __gitcomp "$__git_send_email_confirm_options"
1667                return
1668                ;;
1669        sendemail.suppresscc)
1670                __gitcomp "$__git_send_email_suppresscc_options"
1671                return
1672                ;;
1673        --get|--get-all|--unset|--unset-all)
1674                __gitcomp_nl "$(__git_config_get_set_variables)"
1675                return
1676                ;;
1677        *.*)
1678                COMPREPLY=()
1679                return
1680                ;;
1681        esac
1682        case "$cur" in
1683        --*)
1684                __gitcomp "
1685                        --global --system --file=
1686                        --list --replace-all
1687                        --get --get-all --get-regexp
1688                        --add --unset --unset-all
1689                        --remove-section --rename-section
1690                        "
1691                return
1692                ;;
1693        branch.*.*)
1694                local pfx="${cur%.*}." cur_="${cur##*.}"
1695                __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1696                return
1697                ;;
1698        branch.*)
1699                local pfx="${cur%.*}." cur_="${cur#*.}"
1700                __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1701                return
1702                ;;
1703        guitool.*.*)
1704                local pfx="${cur%.*}." cur_="${cur##*.}"
1705                __gitcomp "
1706                        argprompt cmd confirm needsfile noconsole norescan
1707                        prompt revprompt revunmerged title
1708                        " "$pfx" "$cur_"
1709                return
1710                ;;
1711        difftool.*.*)
1712                local pfx="${cur%.*}." cur_="${cur##*.}"
1713                __gitcomp "cmd path" "$pfx" "$cur_"
1714                return
1715                ;;
1716        man.*.*)
1717                local pfx="${cur%.*}." cur_="${cur##*.}"
1718                __gitcomp "cmd path" "$pfx" "$cur_"
1719                return
1720                ;;
1721        mergetool.*.*)
1722                local pfx="${cur%.*}." cur_="${cur##*.}"
1723                __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1724                return
1725                ;;
1726        pager.*)
1727                local pfx="${cur%.*}." cur_="${cur#*.}"
1728                __git_compute_all_commands
1729                __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1730                return
1731                ;;
1732        remote.*.*)
1733                local pfx="${cur%.*}." cur_="${cur##*.}"
1734                __gitcomp "
1735                        url proxy fetch push mirror skipDefaultUpdate
1736                        receivepack uploadpack tagopt pushurl
1737                        " "$pfx" "$cur_"
1738                return
1739                ;;
1740        remote.*)
1741                local pfx="${cur%.*}." cur_="${cur#*.}"
1742                __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1743                return
1744                ;;
1745        url.*.*)
1746                local pfx="${cur%.*}." cur_="${cur##*.}"
1747                __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1748                return
1749                ;;
1750        esac
1751        __gitcomp "
1752                add.ignoreErrors
1753                advice.commitBeforeMerge
1754                advice.detachedHead
1755                advice.implicitIdentity
1756                advice.pushNonFastForward
1757                advice.resolveConflict
1758                advice.statusHints
1759                alias.
1760                am.keepcr
1761                apply.ignorewhitespace
1762                apply.whitespace
1763                branch.autosetupmerge
1764                branch.autosetuprebase
1765                browser.
1766                clean.requireForce
1767                color.branch
1768                color.branch.current
1769                color.branch.local
1770                color.branch.plain
1771                color.branch.remote
1772                color.decorate.HEAD
1773                color.decorate.branch
1774                color.decorate.remoteBranch
1775                color.decorate.stash
1776                color.decorate.tag
1777                color.diff
1778                color.diff.commit
1779                color.diff.frag
1780                color.diff.func
1781                color.diff.meta
1782                color.diff.new
1783                color.diff.old
1784                color.diff.plain
1785                color.diff.whitespace
1786                color.grep
1787                color.grep.context
1788                color.grep.filename
1789                color.grep.function
1790                color.grep.linenumber
1791                color.grep.match
1792                color.grep.selected
1793                color.grep.separator
1794                color.interactive
1795                color.interactive.error
1796                color.interactive.header
1797                color.interactive.help
1798                color.interactive.prompt
1799                color.pager
1800                color.showbranch
1801                color.status
1802                color.status.added
1803                color.status.changed
1804                color.status.header
1805                color.status.nobranch
1806                color.status.untracked
1807                color.status.updated
1808                color.ui
1809                commit.status
1810                commit.template
1811                core.abbrev
1812                core.askpass
1813                core.attributesfile
1814                core.autocrlf
1815                core.bare
1816                core.bigFileThreshold
1817                core.compression
1818                core.createObject
1819                core.deltaBaseCacheLimit
1820                core.editor
1821                core.eol
1822                core.excludesfile
1823                core.fileMode
1824                core.fsyncobjectfiles
1825                core.gitProxy
1826                core.ignoreCygwinFSTricks
1827                core.ignoreStat
1828                core.ignorecase
1829                core.logAllRefUpdates
1830                core.loosecompression
1831                core.notesRef
1832                core.packedGitLimit
1833                core.packedGitWindowSize
1834                core.pager
1835                core.preferSymlinkRefs
1836                core.preloadindex
1837                core.quotepath
1838                core.repositoryFormatVersion
1839                core.safecrlf
1840                core.sharedRepository
1841                core.sparseCheckout
1842                core.symlinks
1843                core.trustctime
1844                core.warnAmbiguousRefs
1845                core.whitespace
1846                core.worktree
1847                diff.autorefreshindex
1848                diff.statGraphWidth
1849                diff.external
1850                diff.ignoreSubmodules
1851                diff.mnemonicprefix
1852                diff.noprefix
1853                diff.renameLimit
1854                diff.renames
1855                diff.suppressBlankEmpty
1856                diff.tool
1857                diff.wordRegex
1858                difftool.
1859                difftool.prompt
1860                fetch.recurseSubmodules
1861                fetch.unpackLimit
1862                format.attach
1863                format.cc
1864                format.headers
1865                format.numbered
1866                format.pretty
1867                format.signature
1868                format.signoff
1869                format.subjectprefix
1870                format.suffix
1871                format.thread
1872                format.to
1873                gc.
1874                gc.aggressiveWindow
1875                gc.auto
1876                gc.autopacklimit
1877                gc.packrefs
1878                gc.pruneexpire
1879                gc.reflogexpire
1880                gc.reflogexpireunreachable
1881                gc.rerereresolved
1882                gc.rerereunresolved
1883                gitcvs.allbinary
1884                gitcvs.commitmsgannotation
1885                gitcvs.dbTableNamePrefix
1886                gitcvs.dbdriver
1887                gitcvs.dbname
1888                gitcvs.dbpass
1889                gitcvs.dbuser
1890                gitcvs.enabled
1891                gitcvs.logfile
1892                gitcvs.usecrlfattr
1893                guitool.
1894                gui.blamehistoryctx
1895                gui.commitmsgwidth
1896                gui.copyblamethreshold
1897                gui.diffcontext
1898                gui.encoding
1899                gui.fastcopyblame
1900                gui.matchtrackingbranch
1901                gui.newbranchtemplate
1902                gui.pruneduringfetch
1903                gui.spellingdictionary
1904                gui.trustmtime
1905                help.autocorrect
1906                help.browser
1907                help.format
1908                http.lowSpeedLimit
1909                http.lowSpeedTime
1910                http.maxRequests
1911                http.minSessions
1912                http.noEPSV
1913                http.postBuffer
1914                http.proxy
1915                http.sslCAInfo
1916                http.sslCAPath
1917                http.sslCert
1918                http.sslCertPasswordProtected
1919                http.sslKey
1920                http.sslVerify
1921                http.useragent
1922                i18n.commitEncoding
1923                i18n.logOutputEncoding
1924                imap.authMethod
1925                imap.folder
1926                imap.host
1927                imap.pass
1928                imap.port
1929                imap.preformattedHTML
1930                imap.sslverify
1931                imap.tunnel
1932                imap.user
1933                init.templatedir
1934                instaweb.browser
1935                instaweb.httpd
1936                instaweb.local
1937                instaweb.modulepath
1938                instaweb.port
1939                interactive.singlekey
1940                log.date
1941                log.decorate
1942                log.showroot
1943                mailmap.file
1944                man.
1945                man.viewer
1946                merge.
1947                merge.conflictstyle
1948                merge.log
1949                merge.renameLimit
1950                merge.renormalize
1951                merge.stat
1952                merge.tool
1953                merge.verbosity
1954                mergetool.
1955                mergetool.keepBackup
1956                mergetool.keepTemporaries
1957                mergetool.prompt
1958                notes.displayRef
1959                notes.rewrite.
1960                notes.rewrite.amend
1961                notes.rewrite.rebase
1962                notes.rewriteMode
1963                notes.rewriteRef
1964                pack.compression
1965                pack.deltaCacheLimit
1966                pack.deltaCacheSize
1967                pack.depth
1968                pack.indexVersion
1969                pack.packSizeLimit
1970                pack.threads
1971                pack.window
1972                pack.windowMemory
1973                pager.
1974                pretty.
1975                pull.octopus
1976                pull.twohead
1977                push.default
1978                rebase.autosquash
1979                rebase.stat
1980                receive.autogc
1981                receive.denyCurrentBranch
1982                receive.denyDeleteCurrent
1983                receive.denyDeletes
1984                receive.denyNonFastForwards
1985                receive.fsckObjects
1986                receive.unpackLimit
1987                receive.updateserverinfo
1988                remotes.
1989                repack.usedeltabaseoffset
1990                rerere.autoupdate
1991                rerere.enabled
1992                sendemail.
1993                sendemail.aliasesfile
1994                sendemail.aliasfiletype
1995                sendemail.bcc
1996                sendemail.cc
1997                sendemail.cccmd
1998                sendemail.chainreplyto
1999                sendemail.confirm
2000                sendemail.envelopesender
2001                sendemail.from
2002                sendemail.identity
2003                sendemail.multiedit
2004                sendemail.signedoffbycc
2005                sendemail.smtpdomain
2006                sendemail.smtpencryption
2007                sendemail.smtppass
2008                sendemail.smtpserver
2009                sendemail.smtpserveroption
2010                sendemail.smtpserverport
2011                sendemail.smtpuser
2012                sendemail.suppresscc
2013                sendemail.suppressfrom
2014                sendemail.thread
2015                sendemail.to
2016                sendemail.validate
2017                showbranch.default
2018                status.relativePaths
2019                status.showUntrackedFiles
2020                status.submodulesummary
2021                submodule.
2022                tar.umask
2023                transfer.unpackLimit
2024                url.
2025                user.email
2026                user.name
2027                user.signingkey
2028                web.browser
2029                branch. remote.
2030        "
2031}
2032
2033_git_remote ()
2034{
2035        local subcommands="add rename rm set-head set-branches set-url show prune update"
2036        local subcommand="$(__git_find_on_cmdline "$subcommands")"
2037        if [ -z "$subcommand" ]; then
2038                __gitcomp "$subcommands"
2039                return
2040        fi
2041
2042        case "$subcommand" in
2043        rename|rm|set-url|show|prune)
2044                __gitcomp_nl "$(__git_remotes)"
2045                ;;
2046        set-head|set-branches)
2047                __git_complete_remote_or_refspec
2048                ;;
2049        update)
2050                local i c='' IFS=$'\n'
2051                for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2052                        i="${i#remotes.}"
2053                        c="$c ${i/ */}"
2054                done
2055                __gitcomp "$c"
2056                ;;
2057        *)
2058                COMPREPLY=()
2059                ;;
2060        esac
2061}
2062
2063_git_replace ()
2064{
2065        __gitcomp_nl "$(__git_refs)"
2066}
2067
2068_git_reset ()
2069{
2070        __git_has_doubledash && return
2071
2072        case "$cur" in
2073        --*)
2074                __gitcomp "--merge --mixed --hard --soft --patch"
2075                return
2076                ;;
2077        esac
2078        __gitcomp_nl "$(__git_refs)"
2079}
2080
2081_git_revert ()
2082{
2083        case "$cur" in
2084        --*)
2085                __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2086                return
2087                ;;
2088        esac
2089        __gitcomp_nl "$(__git_refs)"
2090}
2091
2092_git_rm ()
2093{
2094        __git_has_doubledash && return
2095
2096        case "$cur" in
2097        --*)
2098                __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2099                return
2100                ;;
2101        esac
2102        COMPREPLY=()
2103}
2104
2105_git_shortlog ()
2106{
2107        __git_has_doubledash && return
2108
2109        case "$cur" in
2110        --*)
2111                __gitcomp "
2112                        $__git_log_common_options
2113                        $__git_log_shortlog_options
2114                        --numbered --summary
2115                        "
2116                return
2117                ;;
2118        esac
2119        __git_complete_revlist
2120}
2121
2122_git_show ()
2123{
2124        __git_has_doubledash && return
2125
2126        case "$cur" in
2127        --pretty=*|--format=*)
2128                __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2129                        " "" "${cur#*=}"
2130                return
2131                ;;
2132        --*)
2133                __gitcomp "--pretty= --format= --abbrev-commit --oneline
2134                        $__git_diff_common_options
2135                        "
2136                return
2137                ;;
2138        esac
2139        __git_complete_file
2140}
2141
2142_git_show_branch ()
2143{
2144        case "$cur" in
2145        --*)
2146                __gitcomp "
2147                        --all --remotes --topo-order --current --more=
2148                        --list --independent --merge-base --no-name
2149                        --color --no-color
2150                        --sha1-name --sparse --topics --reflog
2151                        "
2152                return
2153                ;;
2154        esac
2155        __git_complete_revlist
2156}
2157
2158_git_stash ()
2159{
2160        local save_opts='--keep-index --no-keep-index --quiet --patch'
2161        local subcommands='save list show apply clear drop pop create branch'
2162        local subcommand="$(__git_find_on_cmdline "$subcommands")"
2163        if [ -z "$subcommand" ]; then
2164                case "$cur" in
2165                --*)
2166                        __gitcomp "$save_opts"
2167                        ;;
2168                *)
2169                        if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2170                                __gitcomp "$subcommands"
2171                        else
2172                                COMPREPLY=()
2173                        fi
2174                        ;;
2175                esac
2176        else
2177                case "$subcommand,$cur" in
2178                save,--*)
2179                        __gitcomp "$save_opts"
2180                        ;;
2181                apply,--*|pop,--*)
2182                        __gitcomp "--index --quiet"
2183                        ;;
2184                show,--*|drop,--*|branch,--*)
2185                        COMPREPLY=()
2186                        ;;
2187                show,*|apply,*|drop,*|pop,*|branch,*)
2188                        __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2189                                        | sed -n -e 's/:.*//p')"
2190                        ;;
2191                *)
2192                        COMPREPLY=()
2193                        ;;
2194                esac
2195        fi
2196}
2197
2198_git_submodule ()
2199{
2200        __git_has_doubledash && return
2201
2202        local subcommands="add status init update summary foreach sync"
2203        if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2204                case "$cur" in
2205                --*)
2206                        __gitcomp "--quiet --cached"
2207                        ;;
2208                *)
2209                        __gitcomp "$subcommands"
2210                        ;;
2211                esac
2212                return
2213        fi
2214}
2215
2216_git_svn ()
2217{
2218        local subcommands="
2219                init fetch clone rebase dcommit log find-rev
2220                set-tree commit-diff info create-ignore propget
2221                proplist show-ignore show-externals branch tag blame
2222                migrate mkdirs reset gc
2223                "
2224        local subcommand="$(__git_find_on_cmdline "$subcommands")"
2225        if [ -z "$subcommand" ]; then
2226                __gitcomp "$subcommands"
2227        else
2228                local remote_opts="--username= --config-dir= --no-auth-cache"
2229                local fc_opts="
2230                        --follow-parent --authors-file= --repack=
2231                        --no-metadata --use-svm-props --use-svnsync-props
2232                        --log-window-size= --no-checkout --quiet
2233                        --repack-flags --use-log-author --localtime
2234                        --ignore-paths= $remote_opts
2235                        "
2236                local init_opts="
2237                        --template= --shared= --trunk= --tags=
2238                        --branches= --stdlayout --minimize-url
2239                        --no-metadata --use-svm-props --use-svnsync-props
2240                        --rewrite-root= --prefix= --use-log-author
2241                        --add-author-from $remote_opts
2242                        "
2243                local cmt_opts="
2244                        --edit --rmdir --find-copies-harder --copy-similarity=
2245                        "
2246
2247                case "$subcommand,$cur" in
2248                fetch,--*)
2249                        __gitcomp "--revision= --fetch-all $fc_opts"
2250                        ;;
2251                clone,--*)
2252                        __gitcomp "--revision= $fc_opts $init_opts"
2253                        ;;
2254                init,--*)
2255                        __gitcomp "$init_opts"
2256                        ;;
2257                dcommit,--*)
2258                        __gitcomp "
2259                                --merge --strategy= --verbose --dry-run
2260                                --fetch-all --no-rebase --commit-url
2261                                --revision --interactive $cmt_opts $fc_opts
2262                                "
2263                        ;;
2264                set-tree,--*)
2265                        __gitcomp "--stdin $cmt_opts $fc_opts"
2266                        ;;
2267                create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2268                show-externals,--*|mkdirs,--*)
2269                        __gitcomp "--revision="
2270                        ;;
2271                log,--*)
2272                        __gitcomp "
2273                                --limit= --revision= --verbose --incremental
2274                                --oneline --show-commit --non-recursive
2275                                --authors-file= --color
2276                                "
2277                        ;;
2278                rebase,--*)
2279                        __gitcomp "
2280                                --merge --verbose --strategy= --local
2281                                --fetch-all --dry-run $fc_opts
2282                                "
2283                        ;;
2284                commit-diff,--*)
2285                        __gitcomp "--message= --file= --revision= $cmt_opts"
2286                        ;;
2287                info,--*)
2288                        __gitcomp "--url"
2289                        ;;
2290                branch,--*)
2291                        __gitcomp "--dry-run --message --tag"
2292                        ;;
2293                tag,--*)
2294                        __gitcomp "--dry-run --message"
2295                        ;;
2296                blame,--*)
2297                        __gitcomp "--git-format"
2298                        ;;
2299                migrate,--*)
2300                        __gitcomp "
2301                                --config-dir= --ignore-paths= --minimize
2302                                --no-auth-cache --username=
2303                                "
2304                        ;;
2305                reset,--*)
2306                        __gitcomp "--revision= --parent"
2307                        ;;
2308                *)
2309                        COMPREPLY=()
2310                        ;;
2311                esac
2312        fi
2313}
2314
2315_git_tag ()
2316{
2317        local i c=1 f=0
2318        while [ $c -lt $cword ]; do
2319                i="${words[c]}"
2320                case "$i" in
2321                -d|-v)
2322                        __gitcomp_nl "$(__git_tags)"
2323                        return
2324                        ;;
2325                -f)
2326                        f=1
2327                        ;;
2328                esac
2329                ((c++))
2330        done
2331
2332        case "$prev" in
2333        -m|-F)
2334                COMPREPLY=()
2335                ;;
2336        -*|tag)
2337                if [ $f = 1 ]; then
2338                        __gitcomp_nl "$(__git_tags)"
2339                else
2340                        COMPREPLY=()
2341                fi
2342                ;;
2343        *)
2344                __gitcomp_nl "$(__git_refs)"
2345                ;;
2346        esac
2347}
2348
2349_git_whatchanged ()
2350{
2351        _git_log
2352}
2353
2354__git_main ()
2355{
2356        local i c=1 command __git_dir
2357
2358        while [ $c -lt $cword ]; do
2359                i="${words[c]}"
2360                case "$i" in
2361                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2362                --bare)      __git_dir="." ;;
2363                --help) command="help"; break ;;
2364                -c) c=$((++c)) ;;
2365                -*) ;;
2366                *) command="$i"; break ;;
2367                esac
2368                ((c++))
2369        done
2370
2371        if [ -z "$command" ]; then
2372                case "$cur" in
2373                --*)   __gitcomp "
2374                        --paginate
2375                        --no-pager
2376                        --git-dir=
2377                        --bare
2378                        --version
2379                        --exec-path
2380                        --exec-path=
2381                        --html-path
2382                        --info-path
2383                        --work-tree=
2384                        --namespace=
2385                        --no-replace-objects
2386                        --help
2387                        "
2388                        ;;
2389                *)     __git_compute_porcelain_commands
2390                       __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2391                esac
2392                return
2393        fi
2394
2395        local completion_func="_git_${command//-/_}"
2396        declare -f $completion_func >/dev/null && $completion_func && return
2397
2398        local expansion=$(__git_aliased_command "$command")
2399        if [ -n "$expansion" ]; then
2400                completion_func="_git_${expansion//-/_}"
2401                declare -f $completion_func >/dev/null && $completion_func
2402        fi
2403}
2404
2405__gitk_main ()
2406{
2407        __git_has_doubledash && return
2408
2409        local g="$(__gitdir)"
2410        local merge=""
2411        if [ -f "$g/MERGE_HEAD" ]; then
2412                merge="--merge"
2413        fi
2414        case "$cur" in
2415        --*)
2416                __gitcomp "
2417                        $__git_log_common_options
2418                        $__git_log_gitk_options
2419                        $merge
2420                        "
2421                return
2422                ;;
2423        esac
2424        __git_complete_revlist
2425}
2426
2427__git_func_wrap ()
2428{
2429        if [[ -n ${ZSH_VERSION-} ]]; then
2430                emulate -L bash
2431                setopt KSH_TYPESET
2432
2433                # workaround zsh's bug that leaves 'words' as a special
2434                # variable in versions < 4.3.12
2435                typeset -h words
2436
2437                # workaround zsh's bug that quotes spaces in the COMPREPLY
2438                # array if IFS doesn't contain spaces.
2439                typeset -h IFS
2440        fi
2441        local cur words cword prev
2442        _get_comp_words_by_ref -n =: cur words cword prev
2443        $1
2444}
2445
2446# Setup completion for certain functions defined above by setting common
2447# variables and workarounds.
2448# This is NOT a public function; use at your own risk.
2449__git_complete ()
2450{
2451        local wrapper="__git_wrap${2}"
2452        eval "$wrapper () { __git_func_wrap $2 ; }"
2453        complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2454                || complete -o default -o nospace -F $wrapper $1
2455}
2456
2457# wrapper for backwards compatibility
2458_git ()
2459{
2460        __git_wrap__git_main
2461}
2462
2463# wrapper for backwards compatibility
2464_gitk ()
2465{
2466        __git_wrap__gitk_main
2467}
2468
2469__git_complete git __git_main
2470__git_complete gitk __gitk_main
2471
2472# The following are necessary only for Cygwin, and only are needed
2473# when the user has tab-completed the executable name and consequently
2474# included the '.exe' suffix.
2475#
2476if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2477__git_complete git.exe __git_main
2478fi