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