contrib / completion / git-completion.bashon commit bash completion: Add 'workflows' to 'git help' (99f0b59)
   1#
   2# bash completion support for core Git.
   3#
   4# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
   5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
   6# Distributed under the GNU General Public License, version 2.0.
   7#
   8# The contained completion routines provide support for completing:
   9#
  10#    *) local and remote branch names
  11#    *) local and remote tag names
  12#    *) .git/remotes file names
  13#    *) git 'subcommands'
  14#    *) tree paths within 'ref:path/to/file' expressions
  15#    *) common --long-options
  16#
  17# To use these routines:
  18#
  19#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  20#    2) Added the following line to your .bashrc:
  21#        source ~/.git-completion.sh
  22#
  23#    3) You may want to make sure the git executable is available
  24#       in your PATH before this script is sourced, as some caching
  25#       is performed while the script loads.  If git isn't found
  26#       at source time then all lookups will be done on demand,
  27#       which may be slightly slower.
  28#
  29#    4) Consider changing your PS1 to also show the current branch:
  30#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  31#
  32#       The argument to __git_ps1 will be displayed only if you
  33#       are currently in a git repository.  The %s token will be
  34#       the name of the current branch.
  35#
  36# To submit patches:
  37#
  38#    *) Read Documentation/SubmittingPatches
  39#    *) Send all patches to the current maintainer:
  40#
  41#       "Shawn O. Pearce" <spearce@spearce.org>
  42#
  43#    *) Always CC the Git mailing list:
  44#
  45#       git@vger.kernel.org
  46#
  47
  48case "$COMP_WORDBREAKS" in
  49*:*) : great ;;
  50*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  51esac
  52
  53__gitdir ()
  54{
  55        if [ -z "$1" ]; then
  56                if [ -n "$__git_dir" ]; then
  57                        echo "$__git_dir"
  58                elif [ -d .git ]; then
  59                        echo .git
  60                else
  61                        git rev-parse --git-dir 2>/dev/null
  62                fi
  63        elif [ -d "$1/.git" ]; then
  64                echo "$1/.git"
  65        else
  66                echo "$1"
  67        fi
  68}
  69
  70__git_ps1 ()
  71{
  72        local g="$(git rev-parse --git-dir 2>/dev/null)"
  73        if [ -n "$g" ]; then
  74                local r
  75                local b
  76                if [ -d "$g/rebase-apply" ]
  77                then
  78                        if test -f "$g/rebase-apply/rebasing"
  79                        then
  80                                r="|REBASE"
  81                        elif test -f "$g/rebase-apply/applying"
  82                        then
  83                                r="|AM"
  84                        else
  85                                r="|AM/REBASE"
  86                        fi
  87                        b="$(git symbolic-ref HEAD 2>/dev/null)"
  88                elif [ -f "$g/rebase-merge/interactive" ]
  89                then
  90                        r="|REBASE-i"
  91                        b="$(cat "$g/rebase-merge/head-name")"
  92                elif [ -d "$g/rebase-merge" ]
  93                then
  94                        r="|REBASE-m"
  95                        b="$(cat "$g/rebase-merge/head-name")"
  96                elif [ -f "$g/MERGE_HEAD" ]
  97                then
  98                        r="|MERGING"
  99                        b="$(git symbolic-ref HEAD 2>/dev/null)"
 100                else
 101                        if [ -f "$g/BISECT_LOG" ]
 102                        then
 103                                r="|BISECTING"
 104                        fi
 105                        if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
 106                        then
 107                                if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
 108                                then
 109                                        b="$(cut -c1-7 "$g/HEAD")..."
 110                                fi
 111                        fi
 112                fi
 113
 114                if [ -n "$1" ]; then
 115                        printf "$1" "${b##refs/heads/}$r"
 116                else
 117                        printf " (%s)" "${b##refs/heads/}$r"
 118                fi
 119        fi
 120}
 121
 122__gitcomp_1 ()
 123{
 124        local c IFS=' '$'\t'$'\n'
 125        for c in $1; do
 126                case "$c$2" in
 127                --*=*) printf %s$'\n' "$c$2" ;;
 128                *.)    printf %s$'\n' "$c$2" ;;
 129                *)     printf %s$'\n' "$c$2 " ;;
 130                esac
 131        done
 132}
 133
 134__gitcomp ()
 135{
 136        local cur="${COMP_WORDS[COMP_CWORD]}"
 137        if [ $# -gt 2 ]; then
 138                cur="$3"
 139        fi
 140        case "$cur" in
 141        --*=)
 142                COMPREPLY=()
 143                ;;
 144        *)
 145                local IFS=$'\n'
 146                COMPREPLY=($(compgen -P "$2" \
 147                        -W "$(__gitcomp_1 "$1" "$4")" \
 148                        -- "$cur"))
 149                ;;
 150        esac
 151}
 152
 153__git_heads ()
 154{
 155        local cmd i is_hash=y dir="$(__gitdir "$1")"
 156        if [ -d "$dir" ]; then
 157                git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
 158                        refs/heads
 159                return
 160        fi
 161        for i in $(git ls-remote "$1" 2>/dev/null); do
 162                case "$is_hash,$i" in
 163                y,*) is_hash=n ;;
 164                n,*^{}) is_hash=y ;;
 165                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
 166                n,*) is_hash=y; echo "$i" ;;
 167                esac
 168        done
 169}
 170
 171__git_tags ()
 172{
 173        local cmd i is_hash=y dir="$(__gitdir "$1")"
 174        if [ -d "$dir" ]; then
 175                git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
 176                        refs/tags
 177                return
 178        fi
 179        for i in $(git ls-remote "$1" 2>/dev/null); do
 180                case "$is_hash,$i" in
 181                y,*) is_hash=n ;;
 182                n,*^{}) is_hash=y ;;
 183                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 184                n,*) is_hash=y; echo "$i" ;;
 185                esac
 186        done
 187}
 188
 189__git_refs ()
 190{
 191        local cmd i is_hash=y dir="$(__gitdir "$1")"
 192        if [ -d "$dir" ]; then
 193                if [ -e "$dir/HEAD" ]; then echo HEAD; fi
 194                git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
 195                        refs/tags refs/heads refs/remotes
 196                return
 197        fi
 198        for i in $(git ls-remote "$dir" 2>/dev/null); do
 199                case "$is_hash,$i" in
 200                y,*) is_hash=n ;;
 201                n,*^{}) is_hash=y ;;
 202                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 203                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
 204                n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
 205                n,*) is_hash=y; echo "$i" ;;
 206                esac
 207        done
 208}
 209
 210__git_refs2 ()
 211{
 212        local i
 213        for i in $(__git_refs "$1"); do
 214                echo "$i:$i"
 215        done
 216}
 217
 218__git_refs_remotes ()
 219{
 220        local cmd i is_hash=y
 221        for i in $(git ls-remote "$1" 2>/dev/null); do
 222                case "$is_hash,$i" in
 223                n,refs/heads/*)
 224                        is_hash=y
 225                        echo "$i:refs/remotes/$1/${i#refs/heads/}"
 226                        ;;
 227                y,*) is_hash=n ;;
 228                n,*^{}) is_hash=y ;;
 229                n,refs/tags/*) is_hash=y;;
 230                n,*) is_hash=y; ;;
 231                esac
 232        done
 233}
 234
 235__git_remotes ()
 236{
 237        local i ngoff IFS=$'\n' d="$(__gitdir)"
 238        shopt -q nullglob || ngoff=1
 239        shopt -s nullglob
 240        for i in "$d/remotes"/*; do
 241                echo ${i#$d/remotes/}
 242        done
 243        [ "$ngoff" ] && shopt -u nullglob
 244        for i in $(git --git-dir="$d" config --list); do
 245                case "$i" in
 246                remote.*.url=*)
 247                        i="${i#remote.}"
 248                        echo "${i/.url=*/}"
 249                        ;;
 250                esac
 251        done
 252}
 253
 254__git_merge_strategies ()
 255{
 256        if [ -n "$__git_merge_strategylist" ]; then
 257                echo "$__git_merge_strategylist"
 258                return
 259        fi
 260        git merge -s help 2>&1 |
 261        sed -n -e '/[Aa]vailable strategies are: /,/^$/{
 262                s/\.$//
 263                s/.*://
 264                s/^[    ]*//
 265                s/[     ]*$//
 266                p
 267        }'
 268}
 269__git_merge_strategylist=
 270__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
 271
 272__git_complete_file ()
 273{
 274        local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
 275        case "$cur" in
 276        ?*:*)
 277                ref="${cur%%:*}"
 278                cur="${cur#*:}"
 279                case "$cur" in
 280                ?*/*)
 281                        pfx="${cur%/*}"
 282                        cur="${cur##*/}"
 283                        ls="$ref:$pfx"
 284                        pfx="$pfx/"
 285                        ;;
 286                *)
 287                        ls="$ref"
 288                        ;;
 289            esac
 290
 291                case "$COMP_WORDBREAKS" in
 292                *:*) : great ;;
 293                *)   pfx="$ref:$pfx" ;;
 294                esac
 295
 296                local IFS=$'\n'
 297                COMPREPLY=($(compgen -P "$pfx" \
 298                        -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 299                                | sed '/^100... blob /{
 300                                           s,^.*        ,,
 301                                           s,$, ,
 302                                       }
 303                                       /^120000 blob /{
 304                                           s,^.*        ,,
 305                                           s,$, ,
 306                                       }
 307                                       /^040000 tree /{
 308                                           s,^.*        ,,
 309                                           s,$,/,
 310                                       }
 311                                       s/^.*    //')" \
 312                        -- "$cur"))
 313                ;;
 314        *)
 315                __gitcomp "$(__git_refs)"
 316                ;;
 317        esac
 318}
 319
 320__git_complete_revlist ()
 321{
 322        local pfx cur="${COMP_WORDS[COMP_CWORD]}"
 323        case "$cur" in
 324        *...*)
 325                pfx="${cur%...*}..."
 326                cur="${cur#*...}"
 327                __gitcomp "$(__git_refs)" "$pfx" "$cur"
 328                ;;
 329        *..*)
 330                pfx="${cur%..*}.."
 331                cur="${cur#*..}"
 332                __gitcomp "$(__git_refs)" "$pfx" "$cur"
 333                ;;
 334        *)
 335                __gitcomp "$(__git_refs)"
 336                ;;
 337        esac
 338}
 339
 340__git_all_commands ()
 341{
 342        if [ -n "$__git_all_commandlist" ]; then
 343                echo "$__git_all_commandlist"
 344                return
 345        fi
 346        local i IFS=" "$'\n'
 347        for i in $(git help -a|egrep '^ ')
 348        do
 349                case $i in
 350                *--*)             : helper pattern;;
 351                *) echo $i;;
 352                esac
 353        done
 354}
 355__git_all_commandlist=
 356__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
 357
 358__git_porcelain_commands ()
 359{
 360        if [ -n "$__git_porcelain_commandlist" ]; then
 361                echo "$__git_porcelain_commandlist"
 362                return
 363        fi
 364        local i IFS=" "$'\n'
 365        for i in "help" $(__git_all_commands)
 366        do
 367                case $i in
 368                *--*)             : helper pattern;;
 369                applymbox)        : ask gittus;;
 370                applypatch)       : ask gittus;;
 371                archimport)       : import;;
 372                cat-file)         : plumbing;;
 373                check-attr)       : plumbing;;
 374                check-ref-format) : plumbing;;
 375                checkout-index)   : plumbing;;
 376                commit-tree)      : plumbing;;
 377                count-objects)    : infrequent;;
 378                cvsexportcommit)  : export;;
 379                cvsimport)        : import;;
 380                cvsserver)        : daemon;;
 381                daemon)           : daemon;;
 382                diff-files)       : plumbing;;
 383                diff-index)       : plumbing;;
 384                diff-tree)        : plumbing;;
 385                fast-import)      : import;;
 386                fast-export)      : export;;
 387                fsck-objects)     : plumbing;;
 388                fetch-pack)       : plumbing;;
 389                fmt-merge-msg)    : plumbing;;
 390                for-each-ref)     : plumbing;;
 391                hash-object)      : plumbing;;
 392                http-*)           : transport;;
 393                index-pack)       : plumbing;;
 394                init-db)          : deprecated;;
 395                local-fetch)      : plumbing;;
 396                lost-found)       : infrequent;;
 397                ls-files)         : plumbing;;
 398                ls-remote)        : plumbing;;
 399                ls-tree)          : plumbing;;
 400                mailinfo)         : plumbing;;
 401                mailsplit)        : plumbing;;
 402                merge-*)          : plumbing;;
 403                mktree)           : plumbing;;
 404                mktag)            : plumbing;;
 405                pack-objects)     : plumbing;;
 406                pack-redundant)   : plumbing;;
 407                pack-refs)        : plumbing;;
 408                parse-remote)     : plumbing;;
 409                patch-id)         : plumbing;;
 410                peek-remote)      : plumbing;;
 411                prune)            : plumbing;;
 412                prune-packed)     : plumbing;;
 413                quiltimport)      : import;;
 414                read-tree)        : plumbing;;
 415                receive-pack)     : plumbing;;
 416                reflog)           : plumbing;;
 417                repo-config)      : deprecated;;
 418                rerere)           : plumbing;;
 419                rev-list)         : plumbing;;
 420                rev-parse)        : plumbing;;
 421                runstatus)        : plumbing;;
 422                sh-setup)         : internal;;
 423                shell)            : daemon;;
 424                show-ref)         : plumbing;;
 425                send-pack)        : plumbing;;
 426                show-index)       : plumbing;;
 427                ssh-*)            : transport;;
 428                stripspace)       : plumbing;;
 429                symbolic-ref)     : plumbing;;
 430                tar-tree)         : deprecated;;
 431                unpack-file)      : plumbing;;
 432                unpack-objects)   : plumbing;;
 433                update-index)     : plumbing;;
 434                update-ref)       : plumbing;;
 435                update-server-info) : daemon;;
 436                upload-archive)   : plumbing;;
 437                upload-pack)      : plumbing;;
 438                write-tree)       : plumbing;;
 439                var)              : infrequent;;
 440                verify-pack)      : infrequent;;
 441                verify-tag)       : plumbing;;
 442                *) echo $i;;
 443                esac
 444        done
 445}
 446__git_porcelain_commandlist=
 447__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
 448
 449__git_aliases ()
 450{
 451        local i IFS=$'\n'
 452        for i in $(git --git-dir="$(__gitdir)" config --list); do
 453                case "$i" in
 454                alias.*)
 455                        i="${i#alias.}"
 456                        echo "${i/=*/}"
 457                        ;;
 458                esac
 459        done
 460}
 461
 462__git_aliased_command ()
 463{
 464        local word cmdline=$(git --git-dir="$(__gitdir)" \
 465                config --get "alias.$1")
 466        for word in $cmdline; do
 467                if [ "${word##-*}" ]; then
 468                        echo $word
 469                        return
 470                fi
 471        done
 472}
 473
 474__git_find_subcommand ()
 475{
 476        local word subcommand c=1
 477
 478        while [ $c -lt $COMP_CWORD ]; do
 479                word="${COMP_WORDS[c]}"
 480                for subcommand in $1; do
 481                        if [ "$subcommand" = "$word" ]; then
 482                                echo "$subcommand"
 483                                return
 484                        fi
 485                done
 486                c=$((++c))
 487        done
 488}
 489
 490__git_has_doubledash ()
 491{
 492        local c=1
 493        while [ $c -lt $COMP_CWORD ]; do
 494                if [ "--" = "${COMP_WORDS[c]}" ]; then
 495                        return 0
 496                fi
 497                c=$((++c))
 498        done
 499        return 1
 500}
 501
 502__git_whitespacelist="nowarn warn error error-all fix"
 503
 504_git_am ()
 505{
 506        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
 507        if [ -d "$dir"/rebase-apply ]; then
 508                __gitcomp "--skip --resolved --abort"
 509                return
 510        fi
 511        case "$cur" in
 512        --whitespace=*)
 513                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 514                return
 515                ;;
 516        --*)
 517                __gitcomp "
 518                        --signoff --utf8 --binary --3way --interactive
 519                        --whitespace=
 520                        "
 521                return
 522        esac
 523        COMPREPLY=()
 524}
 525
 526_git_apply ()
 527{
 528        local cur="${COMP_WORDS[COMP_CWORD]}"
 529        case "$cur" in
 530        --whitespace=*)
 531                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 532                return
 533                ;;
 534        --*)
 535                __gitcomp "
 536                        --stat --numstat --summary --check --index
 537                        --cached --index-info --reverse --reject --unidiff-zero
 538                        --apply --no-add --exclude=
 539                        --whitespace= --inaccurate-eof --verbose
 540                        "
 541                return
 542        esac
 543        COMPREPLY=()
 544}
 545
 546_git_add ()
 547{
 548        __git_has_doubledash && return
 549
 550        local cur="${COMP_WORDS[COMP_CWORD]}"
 551        case "$cur" in
 552        --*)
 553                __gitcomp "
 554                        --interactive --refresh --patch --update --dry-run
 555                        --ignore-errors
 556                        "
 557                return
 558        esac
 559        COMPREPLY=()
 560}
 561
 562_git_archive ()
 563{
 564        local cur="${COMP_WORDS[COMP_CWORD]}"
 565        case "$cur" in
 566        --format=*)
 567                __gitcomp "$(git archive --list)" "" "${cur##--format=}"
 568                return
 569                ;;
 570        --remote=*)
 571                __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
 572                return
 573                ;;
 574        --*)
 575                __gitcomp "
 576                        --format= --list --verbose
 577                        --prefix= --remote= --exec=
 578                        "
 579                return
 580                ;;
 581        esac
 582        __git_complete_file
 583}
 584
 585_git_bisect ()
 586{
 587        __git_has_doubledash && return
 588
 589        local subcommands="start bad good skip reset visualize replay log run"
 590        local subcommand="$(__git_find_subcommand "$subcommands")"
 591        if [ -z "$subcommand" ]; then
 592                __gitcomp "$subcommands"
 593                return
 594        fi
 595
 596        case "$subcommand" in
 597        bad|good|reset|skip)
 598                __gitcomp "$(__git_refs)"
 599                ;;
 600        *)
 601                COMPREPLY=()
 602                ;;
 603        esac
 604}
 605
 606_git_branch ()
 607{
 608        local i c=1 only_local_ref="n" has_r="n"
 609
 610        while [ $c -lt $COMP_CWORD ]; do
 611                i="${COMP_WORDS[c]}"
 612                case "$i" in
 613                -d|-m)  only_local_ref="y" ;;
 614                -r)     has_r="y" ;;
 615                esac
 616                c=$((++c))
 617        done
 618
 619        case "${COMP_WORDS[COMP_CWORD]}" in
 620        --*=*)  COMPREPLY=() ;;
 621        --*)
 622                __gitcomp "
 623                        --color --no-color --verbose --abbrev= --no-abbrev
 624                        --track --no-track --contains --merged --no-merged
 625                        "
 626                ;;
 627        *)
 628                if [ $only_local_ref = "y" -a $has_r = "n" ]; then
 629                        __gitcomp "$(__git_heads)"
 630                else
 631                        __gitcomp "$(__git_refs)"
 632                fi
 633                ;;
 634        esac
 635}
 636
 637_git_bundle ()
 638{
 639        local mycword="$COMP_CWORD"
 640        case "${COMP_WORDS[0]}" in
 641        git)
 642                local cmd="${COMP_WORDS[2]}"
 643                mycword="$((mycword-1))"
 644                ;;
 645        git-bundle*)
 646                local cmd="${COMP_WORDS[1]}"
 647                ;;
 648        esac
 649        case "$mycword" in
 650        1)
 651                __gitcomp "create list-heads verify unbundle"
 652                ;;
 653        2)
 654                # looking for a file
 655                ;;
 656        *)
 657                case "$cmd" in
 658                        create)
 659                                __git_complete_revlist
 660                        ;;
 661                esac
 662                ;;
 663        esac
 664}
 665
 666_git_checkout ()
 667{
 668        __git_has_doubledash && return
 669
 670        __gitcomp "$(__git_refs)"
 671}
 672
 673_git_cherry ()
 674{
 675        __gitcomp "$(__git_refs)"
 676}
 677
 678_git_cherry_pick ()
 679{
 680        local cur="${COMP_WORDS[COMP_CWORD]}"
 681        case "$cur" in
 682        --*)
 683                __gitcomp "--edit --no-commit"
 684                ;;
 685        *)
 686                __gitcomp "$(__git_refs)"
 687                ;;
 688        esac
 689}
 690
 691_git_clean ()
 692{
 693        __git_has_doubledash && return
 694
 695        local cur="${COMP_WORDS[COMP_CWORD]}"
 696        case "$cur" in
 697        --*)
 698                __gitcomp "--dry-run --quiet"
 699                return
 700                ;;
 701        esac
 702        COMPREPLY=()
 703}
 704
 705_git_clone ()
 706{
 707        local cur="${COMP_WORDS[COMP_CWORD]}"
 708        case "$cur" in
 709        --*)
 710                __gitcomp "
 711                        --local
 712                        --no-hardlinks
 713                        --shared
 714                        --reference
 715                        --quiet
 716                        --no-checkout
 717                        --bare
 718                        --mirror
 719                        --origin
 720                        --upload-pack
 721                        --template=
 722                        --depth
 723                        "
 724                return
 725                ;;
 726        esac
 727        COMPREPLY=()
 728}
 729
 730_git_commit ()
 731{
 732        __git_has_doubledash && return
 733
 734        local cur="${COMP_WORDS[COMP_CWORD]}"
 735        case "$cur" in
 736        --*)
 737                __gitcomp "
 738                        --all --author= --signoff --verify --no-verify
 739                        --edit --amend --include --only --interactive
 740                        "
 741                return
 742        esac
 743        COMPREPLY=()
 744}
 745
 746_git_describe ()
 747{
 748        local cur="${COMP_WORDS[COMP_CWORD]}"
 749        case "$cur" in
 750        --*)
 751                __gitcomp "
 752                        --all --tags --contains --abbrev= --candidates=
 753                        --exact-match --debug --long --match --always
 754                        "
 755                return
 756        esac
 757        __gitcomp "$(__git_refs)"
 758}
 759
 760_git_diff ()
 761{
 762        __git_has_doubledash && return
 763
 764        local cur="${COMP_WORDS[COMP_CWORD]}"
 765        case "$cur" in
 766        --*)
 767                __gitcomp "--cached --stat --numstat --shortstat --summary
 768                        --patch-with-stat --name-only --name-status --color
 769                        --no-color --color-words --no-renames --check
 770                        --full-index --binary --abbrev --diff-filter=
 771                        --find-copies-harder --pickaxe-all --pickaxe-regex
 772                        --text --ignore-space-at-eol --ignore-space-change
 773                        --ignore-all-space --exit-code --quiet --ext-diff
 774                        --no-ext-diff
 775                        --no-prefix --src-prefix= --dst-prefix=
 776                        --base --ours --theirs
 777                        "
 778                return
 779                ;;
 780        esac
 781        __git_complete_file
 782}
 783
 784_git_fetch ()
 785{
 786        local cur="${COMP_WORDS[COMP_CWORD]}"
 787
 788        if [ "$COMP_CWORD" = 2 ]; then
 789                __gitcomp "$(__git_remotes)"
 790        else
 791                case "$cur" in
 792                *:*)
 793                        local pfx=""
 794                        case "$COMP_WORDBREAKS" in
 795                        *:*) : great ;;
 796                        *)   pfx="${cur%%:*}:" ;;
 797                        esac
 798                        __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
 799                        ;;
 800                *)
 801                        local remote
 802                        case "${COMP_WORDS[0]}" in
 803                        git-fetch) remote="${COMP_WORDS[1]}" ;;
 804                        git)       remote="${COMP_WORDS[2]}" ;;
 805                        esac
 806                        __gitcomp "$(__git_refs2 "$remote")"
 807                        ;;
 808                esac
 809        fi
 810}
 811
 812_git_format_patch ()
 813{
 814        local cur="${COMP_WORDS[COMP_CWORD]}"
 815        case "$cur" in
 816        --*)
 817                __gitcomp "
 818                        --stdout --attach --thread
 819                        --output-directory
 820                        --numbered --start-number
 821                        --numbered-files
 822                        --keep-subject
 823                        --signoff
 824                        --in-reply-to=
 825                        --full-index --binary
 826                        --not --all
 827                        --cover-letter
 828                        --no-prefix --src-prefix= --dst-prefix=
 829                        "
 830                return
 831                ;;
 832        esac
 833        __git_complete_revlist
 834}
 835
 836_git_gc ()
 837{
 838        local cur="${COMP_WORDS[COMP_CWORD]}"
 839        case "$cur" in
 840        --*)
 841                __gitcomp "--prune --aggressive"
 842                return
 843                ;;
 844        esac
 845        COMPREPLY=()
 846}
 847
 848_git_grep ()
 849{
 850        __git_has_doubledash && return
 851
 852        local cur="${COMP_WORDS[COMP_CWORD]}"
 853        case "$cur" in
 854        --*)
 855                __gitcomp "
 856                        --cached
 857                        --text --ignore-case --word-regexp --invert-match
 858                        --full-name
 859                        --extended-regexp --basic-regexp --fixed-strings
 860                        --files-with-matches --name-only
 861                        --files-without-match
 862                        --count
 863                        --and --or --not --all-match
 864                        "
 865                return
 866                ;;
 867        esac
 868        COMPREPLY=()
 869}
 870
 871_git_help ()
 872{
 873        local cur="${COMP_WORDS[COMP_CWORD]}"
 874        case "$cur" in
 875        --*)
 876                __gitcomp "--all --info --man --web"
 877                return
 878                ;;
 879        esac
 880        __gitcomp "$(__git_all_commands)
 881                attributes cli core-tutorial cvs-migration
 882                diffcore gitk glossary hooks ignore modules
 883                repository-layout tutorial tutorial-2
 884                workflows
 885                "
 886}
 887
 888_git_init ()
 889{
 890        local cur="${COMP_WORDS[COMP_CWORD]}"
 891        case "$cur" in
 892        --shared=*)
 893                __gitcomp "
 894                        false true umask group all world everybody
 895                        " "" "${cur##--shared=}"
 896                return
 897                ;;
 898        --*)
 899                __gitcomp "--quiet --bare --template= --shared --shared="
 900                return
 901                ;;
 902        esac
 903        COMPREPLY=()
 904}
 905
 906_git_ls_files ()
 907{
 908        __git_has_doubledash && return
 909
 910        local cur="${COMP_WORDS[COMP_CWORD]}"
 911        case "$cur" in
 912        --*)
 913                __gitcomp "--cached --deleted --modified --others --ignored
 914                        --stage --directory --no-empty-directory --unmerged
 915                        --killed --exclude= --exclude-from=
 916                        --exclude-per-directory= --exclude-standard
 917                        --error-unmatch --with-tree= --full-name
 918                        --abbrev --ignored --exclude-per-directory
 919                        "
 920                return
 921                ;;
 922        esac
 923        COMPREPLY=()
 924}
 925
 926_git_ls_remote ()
 927{
 928        __gitcomp "$(__git_remotes)"
 929}
 930
 931_git_ls_tree ()
 932{
 933        __git_complete_file
 934}
 935
 936_git_log ()
 937{
 938        __git_has_doubledash && return
 939
 940        local cur="${COMP_WORDS[COMP_CWORD]}"
 941        case "$cur" in
 942        --pretty=*)
 943                __gitcomp "
 944                        oneline short medium full fuller email raw
 945                        " "" "${cur##--pretty=}"
 946                return
 947                ;;
 948        --date=*)
 949                __gitcomp "
 950                        relative iso8601 rfc2822 short local default
 951                " "" "${cur##--date=}"
 952                return
 953                ;;
 954        --*)
 955                __gitcomp "
 956                        --max-count= --max-age= --since= --after=
 957                        --min-age= --before= --until=
 958                        --root --topo-order --date-order --reverse
 959                        --no-merges --follow
 960                        --abbrev-commit --abbrev=
 961                        --relative-date --date=
 962                        --author= --committer= --grep=
 963                        --all-match
 964                        --pretty= --name-status --name-only --raw
 965                        --not --all
 966                        --left-right --cherry-pick
 967                        --graph
 968                        --stat --numstat --shortstat
 969                        --decorate --diff-filter=
 970                        --color-words --walk-reflogs
 971                        --parents --children --full-history
 972                        --merge
 973                        "
 974                return
 975                ;;
 976        esac
 977        __git_complete_revlist
 978}
 979
 980_git_merge ()
 981{
 982        local cur="${COMP_WORDS[COMP_CWORD]}"
 983        case "${COMP_WORDS[COMP_CWORD-1]}" in
 984        -s|--strategy)
 985                __gitcomp "$(__git_merge_strategies)"
 986                return
 987        esac
 988        case "$cur" in
 989        --strategy=*)
 990                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
 991                return
 992                ;;
 993        --*)
 994                __gitcomp "
 995                        --no-commit --no-stat --log --no-log --squash --strategy
 996                        "
 997                return
 998        esac
 999        __gitcomp "$(__git_refs)"
1000}
1001
1002_git_mergetool ()
1003{
1004        local cur="${COMP_WORDS[COMP_CWORD]}"
1005        case "$cur" in
1006        --tool=*)
1007                __gitcomp "
1008                        kdiff3 tkdiff meld xxdiff emerge
1009                        vimdiff gvimdiff ecmerge opendiff
1010                        " "" "${cur##--tool=}"
1011                return
1012                ;;
1013        --*)
1014                __gitcomp "--tool="
1015                return
1016                ;;
1017        esac
1018        COMPREPLY=()
1019}
1020
1021_git_merge_base ()
1022{
1023        __gitcomp "$(__git_refs)"
1024}
1025
1026_git_mv ()
1027{
1028        local cur="${COMP_WORDS[COMP_CWORD]}"
1029        case "$cur" in
1030        --*)
1031                __gitcomp "--dry-run"
1032                return
1033                ;;
1034        esac
1035        COMPREPLY=()
1036}
1037
1038_git_name_rev ()
1039{
1040        __gitcomp "--tags --all --stdin"
1041}
1042
1043_git_pull ()
1044{
1045        local cur="${COMP_WORDS[COMP_CWORD]}"
1046
1047        if [ "$COMP_CWORD" = 2 ]; then
1048                __gitcomp "$(__git_remotes)"
1049        else
1050                local remote
1051                case "${COMP_WORDS[0]}" in
1052                git-pull)  remote="${COMP_WORDS[1]}" ;;
1053                git)       remote="${COMP_WORDS[2]}" ;;
1054                esac
1055                __gitcomp "$(__git_refs "$remote")"
1056        fi
1057}
1058
1059_git_push ()
1060{
1061        local cur="${COMP_WORDS[COMP_CWORD]}"
1062
1063        if [ "$COMP_CWORD" = 2 ]; then
1064                __gitcomp "$(__git_remotes)"
1065        else
1066                case "$cur" in
1067                *:*)
1068                        local remote
1069                        case "${COMP_WORDS[0]}" in
1070                        git-push)  remote="${COMP_WORDS[1]}" ;;
1071                        git)       remote="${COMP_WORDS[2]}" ;;
1072                        esac
1073
1074                        local pfx=""
1075                        case "$COMP_WORDBREAKS" in
1076                        *:*) : great ;;
1077                        *)   pfx="${cur%%:*}:" ;;
1078                        esac
1079
1080                        __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
1081                        ;;
1082                +*)
1083                        __gitcomp "$(__git_refs)" + "${cur#+}"
1084                        ;;
1085                *)
1086                        __gitcomp "$(__git_refs)"
1087                        ;;
1088                esac
1089        fi
1090}
1091
1092_git_rebase ()
1093{
1094        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1095        if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1096                __gitcomp "--continue --skip --abort"
1097                return
1098        fi
1099        case "${COMP_WORDS[COMP_CWORD-1]}" in
1100        -s|--strategy)
1101                __gitcomp "$(__git_merge_strategies)"
1102                return
1103        esac
1104        case "$cur" in
1105        --strategy=*)
1106                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1107                return
1108                ;;
1109        --*)
1110                __gitcomp "--onto --merge --strategy --interactive"
1111                return
1112        esac
1113        __gitcomp "$(__git_refs)"
1114}
1115
1116_git_send_email ()
1117{
1118        local cur="${COMP_WORDS[COMP_CWORD]}"
1119        case "$cur" in
1120        --*)
1121                __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1122                        --dry-run --envelope-sender --from --identity
1123                        --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1124                        --no-suppress-from --no-thread --quiet
1125                        --signed-off-by-cc --smtp-pass --smtp-server
1126                        --smtp-server-port --smtp-ssl --smtp-user --subject
1127                        --suppress-cc --suppress-from --thread --to
1128                        --validate --no-validate"
1129                return
1130                ;;
1131        esac
1132        COMPREPLY=()
1133}
1134
1135_git_config ()
1136{
1137        local cur="${COMP_WORDS[COMP_CWORD]}"
1138        local prv="${COMP_WORDS[COMP_CWORD-1]}"
1139        case "$prv" in
1140        branch.*.remote)
1141                __gitcomp "$(__git_remotes)"
1142                return
1143                ;;
1144        branch.*.merge)
1145                __gitcomp "$(__git_refs)"
1146                return
1147                ;;
1148        remote.*.fetch)
1149                local remote="${prv#remote.}"
1150                remote="${remote%.fetch}"
1151                __gitcomp "$(__git_refs_remotes "$remote")"
1152                return
1153                ;;
1154        remote.*.push)
1155                local remote="${prv#remote.}"
1156                remote="${remote%.push}"
1157                __gitcomp "$(git --git-dir="$(__gitdir)" \
1158                        for-each-ref --format='%(refname):%(refname)' \
1159                        refs/heads)"
1160                return
1161                ;;
1162        pull.twohead|pull.octopus)
1163                __gitcomp "$(__git_merge_strategies)"
1164                return
1165                ;;
1166        color.branch|color.diff|color.status)
1167                __gitcomp "always never auto"
1168                return
1169                ;;
1170        color.*.*)
1171                __gitcomp "
1172                        black red green yellow blue magenta cyan white
1173                        bold dim ul blink reverse
1174                        "
1175                return
1176                ;;
1177        *.*)
1178                COMPREPLY=()
1179                return
1180                ;;
1181        esac
1182        case "$cur" in
1183        --*)
1184                __gitcomp "
1185                        --global --system --file=
1186                        --list --replace-all
1187                        --get --get-all --get-regexp
1188                        --add --unset --unset-all
1189                        --remove-section --rename-section
1190                        "
1191                return
1192                ;;
1193        branch.*.*)
1194                local pfx="${cur%.*}."
1195                cur="${cur##*.}"
1196                __gitcomp "remote merge" "$pfx" "$cur"
1197                return
1198                ;;
1199        branch.*)
1200                local pfx="${cur%.*}."
1201                cur="${cur#*.}"
1202                __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1203                return
1204                ;;
1205        remote.*.*)
1206                local pfx="${cur%.*}."
1207                cur="${cur##*.}"
1208                __gitcomp "
1209                        url fetch push skipDefaultUpdate
1210                        receivepack uploadpack tagopt
1211                        " "$pfx" "$cur"
1212                return
1213                ;;
1214        remote.*)
1215                local pfx="${cur%.*}."
1216                cur="${cur#*.}"
1217                __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1218                return
1219                ;;
1220        esac
1221        __gitcomp "
1222                apply.whitespace
1223                core.fileMode
1224                core.gitProxy
1225                core.ignoreStat
1226                core.preferSymlinkRefs
1227                core.logAllRefUpdates
1228                core.loosecompression
1229                core.repositoryFormatVersion
1230                core.sharedRepository
1231                core.warnAmbiguousRefs
1232                core.compression
1233                core.packedGitWindowSize
1234                core.packedGitLimit
1235                clean.requireForce
1236                color.branch
1237                color.branch.current
1238                color.branch.local
1239                color.branch.remote
1240                color.branch.plain
1241                color.diff
1242                color.diff.plain
1243                color.diff.meta
1244                color.diff.frag
1245                color.diff.old
1246                color.diff.new
1247                color.diff.commit
1248                color.diff.whitespace
1249                color.pager
1250                color.status
1251                color.status.header
1252                color.status.added
1253                color.status.changed
1254                color.status.untracked
1255                diff.renameLimit
1256                diff.renames
1257                fetch.unpackLimit
1258                format.headers
1259                format.subjectprefix
1260                gitcvs.enabled
1261                gitcvs.logfile
1262                gitcvs.allbinary
1263                gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1264                gitcvs.dbtablenameprefix
1265                gc.packrefs
1266                gc.reflogexpire
1267                gc.reflogexpireunreachable
1268                gc.rerereresolved
1269                gc.rerereunresolved
1270                http.sslVerify
1271                http.sslCert
1272                http.sslKey
1273                http.sslCAInfo
1274                http.sslCAPath
1275                http.maxRequests
1276                http.lowSpeedLimit
1277                http.lowSpeedTime
1278                http.noEPSV
1279                i18n.commitEncoding
1280                i18n.logOutputEncoding
1281                log.showroot
1282                merge.tool
1283                merge.summary
1284                merge.verbosity
1285                pack.window
1286                pack.depth
1287                pack.windowMemory
1288                pack.compression
1289                pack.deltaCacheSize
1290                pack.deltaCacheLimit
1291                pull.octopus
1292                pull.twohead
1293                repack.useDeltaBaseOffset
1294                showbranch.default
1295                tar.umask
1296                transfer.unpackLimit
1297                receive.unpackLimit
1298                receive.denyNonFastForwards
1299                user.name
1300                user.email
1301                user.signingkey
1302                branch. remote.
1303        "
1304}
1305
1306_git_remote ()
1307{
1308        local subcommands="add rm show prune update"
1309        local subcommand="$(__git_find_subcommand "$subcommands")"
1310        if [ -z "$subcommand" ]; then
1311                __gitcomp "$subcommands"
1312                return
1313        fi
1314
1315        case "$subcommand" in
1316        rm|show|prune)
1317                __gitcomp "$(__git_remotes)"
1318                ;;
1319        update)
1320                local i c='' IFS=$'\n'
1321                for i in $(git --git-dir="$(__gitdir)" config --list); do
1322                        case "$i" in
1323                        remotes.*)
1324                                i="${i#remotes.}"
1325                                c="$c ${i/=*/}"
1326                                ;;
1327                        esac
1328                done
1329                __gitcomp "$c"
1330                ;;
1331        *)
1332                COMPREPLY=()
1333                ;;
1334        esac
1335}
1336
1337_git_reset ()
1338{
1339        __git_has_doubledash && return
1340
1341        local cur="${COMP_WORDS[COMP_CWORD]}"
1342        case "$cur" in
1343        --*)
1344                __gitcomp "--mixed --hard --soft"
1345                return
1346                ;;
1347        esac
1348        __gitcomp "$(__git_refs)"
1349}
1350
1351_git_revert ()
1352{
1353        local cur="${COMP_WORDS[COMP_CWORD]}"
1354        case "$cur" in
1355        --*)
1356                __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1357                return
1358                ;;
1359        esac
1360        COMPREPLY=()
1361}
1362
1363_git_rm ()
1364{
1365        __git_has_doubledash && return
1366
1367        local cur="${COMP_WORDS[COMP_CWORD]}"
1368        case "$cur" in
1369        --*)
1370                __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1371                return
1372                ;;
1373        esac
1374        COMPREPLY=()
1375}
1376
1377_git_shortlog ()
1378{
1379        __git_has_doubledash && return
1380
1381        local cur="${COMP_WORDS[COMP_CWORD]}"
1382        case "$cur" in
1383        --*)
1384                __gitcomp "
1385                        --max-count= --max-age= --since= --after=
1386                        --min-age= --before= --until=
1387                        --no-merges
1388                        --author= --committer= --grep=
1389                        --all-match
1390                        --not --all
1391                        --numbered --summary
1392                        "
1393                return
1394                ;;
1395        esac
1396        __git_complete_revlist
1397}
1398
1399_git_show ()
1400{
1401        local cur="${COMP_WORDS[COMP_CWORD]}"
1402        case "$cur" in
1403        --pretty=*)
1404                __gitcomp "
1405                        oneline short medium full fuller email raw
1406                        " "" "${cur##--pretty=}"
1407                return
1408                ;;
1409        --*)
1410                __gitcomp "--pretty="
1411                return
1412                ;;
1413        esac
1414        __git_complete_file
1415}
1416
1417_git_show_branch ()
1418{
1419        local cur="${COMP_WORDS[COMP_CWORD]}"
1420        case "$cur" in
1421        --*)
1422                __gitcomp "
1423                        --all --remotes --topo-order --current --more=
1424                        --list --independent --merge-base --no-name
1425                        --sha1-name --topics --reflog
1426                        "
1427                return
1428                ;;
1429        esac
1430        __git_complete_revlist
1431}
1432
1433_git_stash ()
1434{
1435        local subcommands='save list show apply clear drop pop create branch'
1436        local subcommand="$(__git_find_subcommand "$subcommands")"
1437        if [ -z "$subcommand" ]; then
1438                __gitcomp "$subcommands"
1439        else
1440                local cur="${COMP_WORDS[COMP_CWORD]}"
1441                case "$subcommand,$cur" in
1442                save,--*)
1443                        __gitcomp "--keep-index"
1444                        ;;
1445                apply,--*)
1446                        __gitcomp "--index"
1447                        ;;
1448                show,--*|drop,--*|pop,--*|branch,--*)
1449                        COMPREPLY=()
1450                        ;;
1451                show,*|apply,*|drop,*|pop,*|branch,*)
1452                        __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1453                                        | sed -n -e 's/:.*//p')"
1454                        ;;
1455                *)
1456                        COMPREPLY=()
1457                        ;;
1458                esac
1459        fi
1460}
1461
1462_git_submodule ()
1463{
1464        __git_has_doubledash && return
1465
1466        local subcommands="add status init update summary foreach sync"
1467        if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1468                local cur="${COMP_WORDS[COMP_CWORD]}"
1469                case "$cur" in
1470                --*)
1471                        __gitcomp "--quiet --cached"
1472                        ;;
1473                *)
1474                        __gitcomp "$subcommands"
1475                        ;;
1476                esac
1477                return
1478        fi
1479}
1480
1481_git_svn ()
1482{
1483        local subcommands="
1484                init fetch clone rebase dcommit log find-rev
1485                set-tree commit-diff info create-ignore propget
1486                proplist show-ignore show-externals
1487                "
1488        local subcommand="$(__git_find_subcommand "$subcommands")"
1489        if [ -z "$subcommand" ]; then
1490                __gitcomp "$subcommands"
1491        else
1492                local remote_opts="--username= --config-dir= --no-auth-cache"
1493                local fc_opts="
1494                        --follow-parent --authors-file= --repack=
1495                        --no-metadata --use-svm-props --use-svnsync-props
1496                        --log-window-size= --no-checkout --quiet
1497                        --repack-flags --user-log-author $remote_opts
1498                        "
1499                local init_opts="
1500                        --template= --shared= --trunk= --tags=
1501                        --branches= --stdlayout --minimize-url
1502                        --no-metadata --use-svm-props --use-svnsync-props
1503                        --rewrite-root= $remote_opts
1504                        "
1505                local cmt_opts="
1506                        --edit --rmdir --find-copies-harder --copy-similarity=
1507                        "
1508
1509                local cur="${COMP_WORDS[COMP_CWORD]}"
1510                case "$subcommand,$cur" in
1511                fetch,--*)
1512                        __gitcomp "--revision= --fetch-all $fc_opts"
1513                        ;;
1514                clone,--*)
1515                        __gitcomp "--revision= $fc_opts $init_opts"
1516                        ;;
1517                init,--*)
1518                        __gitcomp "$init_opts"
1519                        ;;
1520                dcommit,--*)
1521                        __gitcomp "
1522                                --merge --strategy= --verbose --dry-run
1523                                --fetch-all --no-rebase $cmt_opts $fc_opts
1524                                "
1525                        ;;
1526                set-tree,--*)
1527                        __gitcomp "--stdin $cmt_opts $fc_opts"
1528                        ;;
1529                create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1530                show-externals,--*)
1531                        __gitcomp "--revision="
1532                        ;;
1533                log,--*)
1534                        __gitcomp "
1535                                --limit= --revision= --verbose --incremental
1536                                --oneline --show-commit --non-recursive
1537                                --authors-file=
1538                                "
1539                        ;;
1540                rebase,--*)
1541                        __gitcomp "
1542                                --merge --verbose --strategy= --local
1543                                --fetch-all $fc_opts
1544                                "
1545                        ;;
1546                commit-diff,--*)
1547                        __gitcomp "--message= --file= --revision= $cmt_opts"
1548                        ;;
1549                info,--*)
1550                        __gitcomp "--url"
1551                        ;;
1552                *)
1553                        COMPREPLY=()
1554                        ;;
1555                esac
1556        fi
1557}
1558
1559_git_tag ()
1560{
1561        local i c=1 f=0
1562        while [ $c -lt $COMP_CWORD ]; do
1563                i="${COMP_WORDS[c]}"
1564                case "$i" in
1565                -d|-v)
1566                        __gitcomp "$(__git_tags)"
1567                        return
1568                        ;;
1569                -f)
1570                        f=1
1571                        ;;
1572                esac
1573                c=$((++c))
1574        done
1575
1576        case "${COMP_WORDS[COMP_CWORD-1]}" in
1577        -m|-F)
1578                COMPREPLY=()
1579                ;;
1580        -*|tag|git-tag)
1581                if [ $f = 1 ]; then
1582                        __gitcomp "$(__git_tags)"
1583                else
1584                        COMPREPLY=()
1585                fi
1586                ;;
1587        *)
1588                __gitcomp "$(__git_refs)"
1589                ;;
1590        esac
1591}
1592
1593_git ()
1594{
1595        local i c=1 command __git_dir
1596
1597        while [ $c -lt $COMP_CWORD ]; do
1598                i="${COMP_WORDS[c]}"
1599                case "$i" in
1600                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1601                --bare)      __git_dir="." ;;
1602                --version|-p|--paginate) ;;
1603                --help) command="help"; break ;;
1604                *) command="$i"; break ;;
1605                esac
1606                c=$((++c))
1607        done
1608
1609        if [ -z "$command" ]; then
1610                case "${COMP_WORDS[COMP_CWORD]}" in
1611                --*=*) COMPREPLY=() ;;
1612                --*)   __gitcomp "
1613                        --paginate
1614                        --no-pager
1615                        --git-dir=
1616                        --bare
1617                        --version
1618                        --exec-path
1619                        --work-tree=
1620                        --help
1621                        "
1622                        ;;
1623                *)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1624                esac
1625                return
1626        fi
1627
1628        local expansion=$(__git_aliased_command "$command")
1629        [ "$expansion" ] && command="$expansion"
1630
1631        case "$command" in
1632        am)          _git_am ;;
1633        add)         _git_add ;;
1634        apply)       _git_apply ;;
1635        archive)     _git_archive ;;
1636        bisect)      _git_bisect ;;
1637        bundle)      _git_bundle ;;
1638        branch)      _git_branch ;;
1639        checkout)    _git_checkout ;;
1640        cherry)      _git_cherry ;;
1641        cherry-pick) _git_cherry_pick ;;
1642        clean)       _git_clean ;;
1643        clone)       _git_clone ;;
1644        commit)      _git_commit ;;
1645        config)      _git_config ;;
1646        describe)    _git_describe ;;
1647        diff)        _git_diff ;;
1648        fetch)       _git_fetch ;;
1649        format-patch) _git_format_patch ;;
1650        gc)          _git_gc ;;
1651        grep)        _git_grep ;;
1652        help)        _git_help ;;
1653        init)        _git_init ;;
1654        log)         _git_log ;;
1655        ls-files)    _git_ls_files ;;
1656        ls-remote)   _git_ls_remote ;;
1657        ls-tree)     _git_ls_tree ;;
1658        merge)       _git_merge;;
1659        mergetool)   _git_mergetool;;
1660        merge-base)  _git_merge_base ;;
1661        mv)          _git_mv ;;
1662        name-rev)    _git_name_rev ;;
1663        pull)        _git_pull ;;
1664        push)        _git_push ;;
1665        rebase)      _git_rebase ;;
1666        remote)      _git_remote ;;
1667        reset)       _git_reset ;;
1668        revert)      _git_revert ;;
1669        rm)          _git_rm ;;
1670        send-email)  _git_send_email ;;
1671        shortlog)    _git_shortlog ;;
1672        show)        _git_show ;;
1673        show-branch) _git_show_branch ;;
1674        stash)       _git_stash ;;
1675        submodule)   _git_submodule ;;
1676        svn)         _git_svn ;;
1677        tag)         _git_tag ;;
1678        whatchanged) _git_log ;;
1679        *)           COMPREPLY=() ;;
1680        esac
1681}
1682
1683_gitk ()
1684{
1685        __git_has_doubledash && return
1686
1687        local cur="${COMP_WORDS[COMP_CWORD]}"
1688        local g="$(git rev-parse --git-dir 2>/dev/null)"
1689        local merge=""
1690        if [ -f $g/MERGE_HEAD ]; then
1691                merge="--merge"
1692        fi
1693        case "$cur" in
1694        --*)
1695                __gitcomp "--not --all $merge"
1696                return
1697                ;;
1698        esac
1699        __git_complete_revlist
1700}
1701
1702complete -o default -o nospace -F _git git
1703complete -o default -o nospace -F _gitk gitk
1704
1705# The following are necessary only for Cygwin, and only are needed
1706# when the user has tab-completed the executable name and consequently
1707# included the '.exe' suffix.
1708#
1709if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1710complete -o default -o nospace -F _git git.exe
1711fi