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