382c8177a3fc98636d3ca2928021a21660bcddc8
   1#
   2# bash completion support for core Git.
   3#
   4# Copyright (C) 2006,2007 Shawn Pearce
   5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
   6#
   7# The contained completion routines provide support for completing:
   8#
   9#    *) local and remote branch names
  10#    *) local and remote tag names
  11#    *) .git/remotes file names
  12#    *) git 'subcommands'
  13#    *) tree paths within 'ref:path/to/file' expressions
  14#
  15# To use these routines:
  16#
  17#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  18#    2) Added the following line to your .bashrc:
  19#        source ~/.git-completion.sh
  20#
  21#    3) You may want to make sure the git executable is available
  22#       in your PATH before this script is sourced, as some caching
  23#       is performed while the script loads.  If git isn't found
  24#       at source time then all lookups will be done on demand,
  25#       which may be slightly slower.
  26#
  27#    4) Consider changing your PS1 to also show the current branch:
  28#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  29#
  30#       The argument to __git_ps1 will be displayed only if you
  31#       are currently in a git repository.  The %s token will be
  32#       the name of the current branch.
  33#
  34
  35__gitdir ()
  36{
  37        if [ -z "$1" ]; then
  38                if [ -n "$__git_dir" ]; then
  39                        echo "$__git_dir"
  40                elif [ -d .git ]; then
  41                        echo .git
  42                else
  43                        git rev-parse --git-dir 2>/dev/null
  44                fi
  45        elif [ -d "$1/.git" ]; then
  46                echo "$1/.git"
  47        else
  48                echo "$1"
  49        fi
  50}
  51
  52__git_ps1 ()
  53{
  54        local b="$(git symbolic-ref HEAD 2>/dev/null)"
  55        if [ -n "$b" ]; then
  56                if [ -n "$1" ]; then
  57                        printf "$1" "${b##refs/heads/}"
  58                else
  59                        printf " (%s)" "${b##refs/heads/}"
  60                fi
  61        fi
  62}
  63
  64__gitcomp ()
  65{
  66        local all c s=$'\n' IFS=' '$'\t'$'\n'
  67        for c in $1; do
  68                case "$c" in
  69                --*=*) all="$all$c$s" ;;
  70                *)     all="$all$c $s" ;;
  71                esac
  72        done
  73        IFS=$s
  74        COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
  75        return
  76}
  77
  78__git_heads ()
  79{
  80        local cmd i is_hash=y dir="$(__gitdir "$1")"
  81        if [ -d "$dir" ]; then
  82                for i in $(git --git-dir="$dir" \
  83                        for-each-ref --format='%(refname)' \
  84                        refs/heads ); do
  85                        echo "${i#refs/heads/}"
  86                done
  87                return
  88        fi
  89        for i in $(git-ls-remote "$1" 2>/dev/null); do
  90                case "$is_hash,$i" in
  91                y,*) is_hash=n ;;
  92                n,*^{}) is_hash=y ;;
  93                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  94                n,*) is_hash=y; echo "$i" ;;
  95                esac
  96        done
  97}
  98
  99__git_refs ()
 100{
 101        local cmd i is_hash=y dir="$(__gitdir "$1")"
 102        if [ -d "$dir" ]; then
 103                if [ -e "$dir/HEAD" ]; then echo HEAD; fi
 104                for i in $(git --git-dir="$dir" \
 105                        for-each-ref --format='%(refname)' \
 106                        refs/tags refs/heads refs/remotes); do
 107                        case "$i" in
 108                                refs/tags/*)    echo "${i#refs/tags/}" ;;
 109                                refs/heads/*)   echo "${i#refs/heads/}" ;;
 110                                refs/remotes/*) echo "${i#refs/remotes/}" ;;
 111                                *)              echo "$i" ;;
 112                        esac
 113                done
 114                return
 115        fi
 116        for i in $(git-ls-remote "$dir" 2>/dev/null); do
 117                case "$is_hash,$i" in
 118                y,*) is_hash=n ;;
 119                n,*^{}) is_hash=y ;;
 120                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 121                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
 122                n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
 123                n,*) is_hash=y; echo "$i" ;;
 124                esac
 125        done
 126}
 127
 128__git_refs2 ()
 129{
 130        local i
 131        for i in $(__git_refs "$1"); do
 132                echo "$i:$i"
 133        done
 134}
 135
 136__git_refs_remotes ()
 137{
 138        local cmd i is_hash=y
 139        for i in $(git-ls-remote "$1" 2>/dev/null); do
 140                case "$is_hash,$i" in
 141                n,refs/heads/*)
 142                        is_hash=y
 143                        echo "$i:refs/remotes/$1/${i#refs/heads/}"
 144                        ;;
 145                y,*) is_hash=n ;;
 146                n,*^{}) is_hash=y ;;
 147                n,refs/tags/*) is_hash=y;;
 148                n,*) is_hash=y; ;;
 149                esac
 150        done
 151}
 152
 153__git_remotes ()
 154{
 155        local i ngoff IFS=$'\n' d="$(__gitdir)"
 156        shopt -q nullglob || ngoff=1
 157        shopt -s nullglob
 158        for i in "$d/remotes"/*; do
 159                echo ${i#$d/remotes/}
 160        done
 161        [ "$ngoff" ] && shopt -u nullglob
 162        for i in $(git --git-dir="$d" config --list); do
 163                case "$i" in
 164                remote.*.url=*)
 165                        i="${i#remote.}"
 166                        echo "${i/.url=*/}"
 167                        ;;
 168                esac
 169        done
 170}
 171
 172__git_merge_strategies ()
 173{
 174        if [ -n "$__git_merge_strategylist" ]; then
 175                echo "$__git_merge_strategylist"
 176                return
 177        fi
 178        sed -n "/^all_strategies='/{
 179                s/^all_strategies='//
 180                s/'//
 181                p
 182                q
 183                }" "$(git --exec-path)/git-merge"
 184}
 185__git_merge_strategylist=
 186__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
 187
 188__git_complete_file ()
 189{
 190        local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
 191        case "$cur" in
 192        ?*:*)
 193                ref="${cur%%:*}"
 194                cur="${cur#*:}"
 195                case "$cur" in
 196                ?*/*)
 197                        pfx="${cur%/*}"
 198                        cur="${cur##*/}"
 199                        ls="$ref:$pfx"
 200                        pfx="$pfx/"
 201                        ;;
 202                *)
 203                        ls="$ref"
 204                        ;;
 205            esac
 206                COMPREPLY=($(compgen -P "$pfx" \
 207                        -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 208                                | sed '/^100... blob /s,^.*     ,,
 209                                       /^040000 tree /{
 210                                           s,^.*        ,,
 211                                           s,$,/,
 212                                       }
 213                                       s/^.*    //')" \
 214                        -- "$cur"))
 215                ;;
 216        *)
 217                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 218                ;;
 219        esac
 220}
 221
 222__git_complete_revlist ()
 223{
 224        local pfx cur="${COMP_WORDS[COMP_CWORD]}"
 225        case "$cur" in
 226        *...*)
 227                pfx="${cur%...*}..."
 228                cur="${cur#*...}"
 229                COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
 230                ;;
 231        *..*)
 232                pfx="${cur%..*}.."
 233                cur="${cur#*..}"
 234                COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
 235                ;;
 236        *)
 237                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 238                ;;
 239        esac
 240}
 241
 242__git_commands ()
 243{
 244        if [ -n "$__git_commandlist" ]; then
 245                echo "$__git_commandlist"
 246                return
 247        fi
 248        local i IFS=" "$'\n'
 249        for i in $(git help -a|egrep '^ ')
 250        do
 251                case $i in
 252                add--interactive) : plumbing;;
 253                applymbox)        : ask gittus;;
 254                applypatch)       : ask gittus;;
 255                archimport)       : import;;
 256                cat-file)         : plumbing;;
 257                check-ref-format) : plumbing;;
 258                commit-tree)      : plumbing;;
 259                convert-objects)  : plumbing;;
 260                cvsexportcommit)  : export;;
 261                cvsimport)        : import;;
 262                cvsserver)        : daemon;;
 263                daemon)           : daemon;;
 264                fsck-objects)     : plumbing;;
 265                fetch-pack)       : plumbing;;
 266                fmt-merge-msg)    : plumbing;;
 267                hash-object)      : plumbing;;
 268                http-*)           : transport;;
 269                index-pack)       : plumbing;;
 270                init-db)          : deprecated;;
 271                local-fetch)      : plumbing;;
 272                mailinfo)         : plumbing;;
 273                mailsplit)        : plumbing;;
 274                merge-*)          : plumbing;;
 275                mktree)           : plumbing;;
 276                mktag)            : plumbing;;
 277                pack-objects)     : plumbing;;
 278                pack-redundant)   : plumbing;;
 279                pack-refs)        : plumbing;;
 280                parse-remote)     : plumbing;;
 281                patch-id)         : plumbing;;
 282                peek-remote)      : plumbing;;
 283                prune)            : plumbing;;
 284                prune-packed)     : plumbing;;
 285                quiltimport)      : import;;
 286                read-tree)        : plumbing;;
 287                receive-pack)     : plumbing;;
 288                reflog)           : plumbing;;
 289                repo-config)      : plumbing;;
 290                rerere)           : plumbing;;
 291                rev-list)         : plumbing;;
 292                rev-parse)        : plumbing;;
 293                runstatus)        : plumbing;;
 294                sh-setup)         : internal;;
 295                shell)            : daemon;;
 296                send-pack)        : plumbing;;
 297                show-index)       : plumbing;;
 298                ssh-*)            : transport;;
 299                stripspace)       : plumbing;;
 300                svn)              : import export;;
 301                svnimport)        : import;;
 302                symbolic-ref)     : plumbing;;
 303                tar-tree)         : deprecated;;
 304                unpack-file)      : plumbing;;
 305                unpack-objects)   : plumbing;;
 306                update-index)     : plumbing;;
 307                update-ref)       : plumbing;;
 308                update-server-info) : daemon;;
 309                upload-archive)   : plumbing;;
 310                upload-pack)      : plumbing;;
 311                write-tree)       : plumbing;;
 312                verify-tag)       : plumbing;;
 313                *) echo $i;;
 314                esac
 315        done
 316}
 317__git_commandlist=
 318__git_commandlist="$(__git_commands 2>/dev/null)"
 319
 320__git_aliases ()
 321{
 322        local i IFS=$'\n'
 323        for i in $(git --git-dir="$(__gitdir)" config --list); do
 324                case "$i" in
 325                alias.*)
 326                        i="${i#alias.}"
 327                        echo "${i/=*/}"
 328                        ;;
 329                esac
 330        done
 331}
 332
 333__git_aliased_command ()
 334{
 335        local word cmdline=$(git --git-dir="$(__gitdir)" \
 336                config --get "alias.$1")
 337        for word in $cmdline; do
 338                if [ "${word##-*}" ]; then
 339                        echo $word
 340                        return
 341                fi
 342        done
 343}
 344
 345__git_whitespacelist="nowarn warn error error-all strip"
 346
 347_git_am ()
 348{
 349        local cur="${COMP_WORDS[COMP_CWORD]}"
 350        if [ -d .dotest ]; then
 351                COMPREPLY=($(compgen -W "
 352                        --skip --resolved
 353                        " -- "$cur"))
 354                return
 355        fi
 356        case "$cur" in
 357        --whitespace=*)
 358                COMPREPLY=($(compgen -W "$__git_whitespacelist" \
 359                        -- "${cur##--whitespace=}"))
 360                return
 361                ;;
 362        --*)
 363                COMPREPLY=($(compgen -W "
 364                        --signoff --utf8 --binary --3way --interactive
 365                        --whitespace=
 366                        " -- "$cur"))
 367                return
 368        esac
 369        COMPREPLY=()
 370}
 371
 372_git_apply ()
 373{
 374        local cur="${COMP_WORDS[COMP_CWORD]}"
 375        case "$cur" in
 376        --whitespace=*)
 377                COMPREPLY=($(compgen -W "$__git_whitespacelist" \
 378                        -- "${cur##--whitespace=}"))
 379                return
 380                ;;
 381        --*)
 382                COMPREPLY=($(compgen -W "
 383                        --stat --numstat --summary --check --index
 384                        --cached --index-info --reverse --reject --unidiff-zero
 385                        --apply --no-add --exclude=
 386                        --whitespace= --inaccurate-eof --verbose
 387                        " -- "$cur"))
 388                return
 389        esac
 390        COMPREPLY=()
 391}
 392
 393_git_add ()
 394{
 395        local cur="${COMP_WORDS[COMP_CWORD]}"
 396        case "$cur" in
 397        --*)
 398                COMPREPLY=($(compgen -W "
 399                        --interactive
 400                        " -- "$cur"))
 401                return
 402        esac
 403        COMPREPLY=()
 404}
 405
 406_git_branch ()
 407{
 408        local cur="${COMP_WORDS[COMP_CWORD]}"
 409        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 410}
 411
 412_git_checkout ()
 413{
 414        local cur="${COMP_WORDS[COMP_CWORD]}"
 415        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 416}
 417
 418_git_cherry_pick ()
 419{
 420        local cur="${COMP_WORDS[COMP_CWORD]}"
 421        case "$cur" in
 422        --*)
 423                COMPREPLY=($(compgen -W "
 424                        --edit --no-commit
 425                        " -- "$cur"))
 426                ;;
 427        *)
 428                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 429                ;;
 430        esac
 431}
 432
 433_git_commit ()
 434{
 435        local cur="${COMP_WORDS[COMP_CWORD]}"
 436        case "$cur" in
 437        --*)
 438                COMPREPLY=($(compgen -W "
 439                        --all --author= --signoff --verify --no-verify
 440                        --edit --amend --include --only
 441                        " -- "$cur"))
 442                return
 443        esac
 444        COMPREPLY=()
 445}
 446
 447_git_diff ()
 448{
 449        __git_complete_file
 450}
 451
 452_git_diff_tree ()
 453{
 454        local cur="${COMP_WORDS[COMP_CWORD]}"
 455        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 456}
 457
 458_git_fetch ()
 459{
 460        local cur="${COMP_WORDS[COMP_CWORD]}"
 461
 462        case "${COMP_WORDS[0]},$COMP_CWORD" in
 463        git-fetch*,1)
 464                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 465                ;;
 466        git,2)
 467                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 468                ;;
 469        *)
 470                case "$cur" in
 471                *:*)
 472                        cur="${cur#*:}"
 473                        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 474                        ;;
 475                *)
 476                        local remote
 477                        case "${COMP_WORDS[0]}" in
 478                        git-fetch) remote="${COMP_WORDS[1]}" ;;
 479                        git)       remote="${COMP_WORDS[2]}" ;;
 480                        esac
 481                        COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
 482                        ;;
 483                esac
 484                ;;
 485        esac
 486}
 487
 488_git_format_patch ()
 489{
 490        local cur="${COMP_WORDS[COMP_CWORD]}"
 491        case "$cur" in
 492        --*)
 493                COMPREPLY=($(compgen -W "
 494                        --stdout --attach --thread
 495                        --output-directory
 496                        --numbered --start-number
 497                        --keep-subject
 498                        --signoff
 499                        --in-reply-to=
 500                        --full-index --binary
 501                        " -- "$cur"))
 502                return
 503                ;;
 504        esac
 505        __git_complete_revlist
 506}
 507
 508_git_ls_remote ()
 509{
 510        local cur="${COMP_WORDS[COMP_CWORD]}"
 511        COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 512}
 513
 514_git_ls_tree ()
 515{
 516        __git_complete_file
 517}
 518
 519_git_log ()
 520{
 521        local cur="${COMP_WORDS[COMP_CWORD]}"
 522        case "$cur" in
 523        --pretty=*)
 524                COMPREPLY=($(compgen -W "
 525                        oneline short medium full fuller email raw
 526                        " -- "${cur##--pretty=}"))
 527                return
 528                ;;
 529        --*)
 530                COMPREPLY=($(compgen -W "
 531                        --max-count= --max-age= --since= --after=
 532                        --min-age= --before= --until=
 533                        --root --not --topo-order --date-order
 534                        --no-merges
 535                        --abbrev-commit --abbrev=
 536                        --relative-date
 537                        --author= --committer= --grep=
 538                        --all-match
 539                        --pretty= --name-status --name-only
 540                        " -- "$cur"))
 541                return
 542                ;;
 543        esac
 544        __git_complete_revlist
 545}
 546
 547_git_merge ()
 548{
 549        local cur="${COMP_WORDS[COMP_CWORD]}"
 550        case "${COMP_WORDS[COMP_CWORD-1]}" in
 551        -s|--strategy)
 552                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 553                return
 554        esac
 555        case "$cur" in
 556        --strategy=*)
 557                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 558                        -- "${cur##--strategy=}"))
 559                return
 560                ;;
 561        --*)
 562                COMPREPLY=($(compgen -W "
 563                        --no-commit --no-summary --squash --strategy
 564                        " -- "$cur"))
 565                return
 566        esac
 567        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 568}
 569
 570_git_merge_base ()
 571{
 572        local cur="${COMP_WORDS[COMP_CWORD]}"
 573        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 574}
 575
 576_git_name_rev ()
 577{
 578        local cur="${COMP_WORDS[COMP_CWORD]}"
 579        COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
 580}
 581
 582_git_pull ()
 583{
 584        local cur="${COMP_WORDS[COMP_CWORD]}"
 585
 586        case "${COMP_WORDS[0]},$COMP_CWORD" in
 587        git-pull*,1)
 588                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 589                ;;
 590        git,2)
 591                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 592                ;;
 593        *)
 594                local remote
 595                case "${COMP_WORDS[0]}" in
 596                git-pull)  remote="${COMP_WORDS[1]}" ;;
 597                git)       remote="${COMP_WORDS[2]}" ;;
 598                esac
 599                COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 600                ;;
 601        esac
 602}
 603
 604_git_push ()
 605{
 606        local cur="${COMP_WORDS[COMP_CWORD]}"
 607
 608        case "${COMP_WORDS[0]},$COMP_CWORD" in
 609        git-push*,1)
 610                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 611                ;;
 612        git,2)
 613                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 614                ;;
 615        *)
 616                case "$cur" in
 617                *:*)
 618                        local remote
 619                        case "${COMP_WORDS[0]}" in
 620                        git-push)  remote="${COMP_WORDS[1]}" ;;
 621                        git)       remote="${COMP_WORDS[2]}" ;;
 622                        esac
 623                        cur="${cur#*:}"
 624                        COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 625                        ;;
 626                *)
 627                        COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
 628                        ;;
 629                esac
 630                ;;
 631        esac
 632}
 633
 634_git_rebase ()
 635{
 636        local cur="${COMP_WORDS[COMP_CWORD]}"
 637        if [ -d .dotest ]; then
 638                COMPREPLY=($(compgen -W "
 639                        --continue --skip --abort
 640                        " -- "$cur"))
 641                return
 642        fi
 643        case "${COMP_WORDS[COMP_CWORD-1]}" in
 644        -s|--strategy)
 645                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 646                return
 647        esac
 648        case "$cur" in
 649        --strategy=*)
 650                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 651                        -- "${cur##--strategy=}"))
 652                return
 653                ;;
 654        --*)
 655                COMPREPLY=($(compgen -W "
 656                        --onto --merge --strategy
 657                        " -- "$cur"))
 658                return
 659        esac
 660        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 661}
 662
 663_git_config ()
 664{
 665        local cur="${COMP_WORDS[COMP_CWORD]}"
 666        local prv="${COMP_WORDS[COMP_CWORD-1]}"
 667        case "$prv" in
 668        branch.*.remote)
 669                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 670                return
 671                ;;
 672        branch.*.merge)
 673                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 674                return
 675                ;;
 676        remote.*.fetch)
 677                local remote="${prv#remote.}"
 678                remote="${remote%.fetch}"
 679                COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
 680                        -- "$cur"))
 681                return
 682                ;;
 683        remote.*.push)
 684                local remote="${prv#remote.}"
 685                remote="${remote%.push}"
 686                COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
 687                        for-each-ref --format='%(refname):%(refname)' \
 688                        refs/heads)" -- "$cur"))
 689                return
 690                ;;
 691        *.*)
 692                COMPREPLY=()
 693                return
 694                ;;
 695        esac
 696        case "$cur" in
 697        --*)
 698                COMPREPLY=($(compgen -W "
 699                        --global --list --replace-all
 700                        --get --get-all --get-regexp
 701                        --unset --unset-all
 702                        " -- "$cur"))
 703                return
 704                ;;
 705        branch.*.*)
 706                local pfx="${cur%.*}."
 707                cur="${cur##*.}"
 708                COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
 709                return
 710                ;;
 711        branch.*)
 712                local pfx="${cur%.*}."
 713                cur="${cur#*.}"
 714                COMPREPLY=($(compgen -P "$pfx" -S . \
 715                        -W "$(__git_heads)" -- "$cur"))
 716                return
 717                ;;
 718        remote.*.*)
 719                local pfx="${cur%.*}."
 720                cur="${cur##*.}"
 721                COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
 722                return
 723                ;;
 724        remote.*)
 725                local pfx="${cur%.*}."
 726                cur="${cur#*.}"
 727                COMPREPLY=($(compgen -P "$pfx" -S . \
 728                        -W "$(__git_remotes)" -- "$cur"))
 729                return
 730                ;;
 731        esac
 732        COMPREPLY=($(compgen -W "
 733                apply.whitespace
 734                core.fileMode
 735                core.gitProxy
 736                core.ignoreStat
 737                core.preferSymlinkRefs
 738                core.logAllRefUpdates
 739                core.repositoryFormatVersion
 740                core.sharedRepository
 741                core.warnAmbiguousRefs
 742                core.compression
 743                core.legacyHeaders
 744                i18n.commitEncoding
 745                i18n.logOutputEncoding
 746                diff.color
 747                color.diff
 748                diff.renameLimit
 749                diff.renames
 750                pager.color
 751                color.pager
 752                status.color
 753                color.status
 754                log.showroot
 755                show.difftree
 756                showbranch.default
 757                whatchanged.difftree
 758                http.sslVerify
 759                http.sslCert
 760                http.sslKey
 761                http.sslCAInfo
 762                http.sslCAPath
 763                http.maxRequests
 764                http.lowSpeedLimit http.lowSpeedTime
 765                http.noEPSV
 766                pack.window
 767                repack.useDeltaBaseOffset
 768                pull.octopus pull.twohead
 769                merge.summary
 770                receive.unpackLimit
 771                receive.denyNonFastForwards
 772                user.name user.email
 773                tar.umask
 774                gitcvs.enabled
 775                gitcvs.logfile
 776                branch. remote.
 777        " -- "$cur"))
 778}
 779
 780_git_reset ()
 781{
 782        local cur="${COMP_WORDS[COMP_CWORD]}"
 783        local opt="--mixed --hard --soft"
 784        COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
 785}
 786
 787_git_show ()
 788{
 789        local cur="${COMP_WORDS[COMP_CWORD]}"
 790        case "$cur" in
 791        --pretty=*)
 792                COMPREPLY=($(compgen -W "
 793                        oneline short medium full fuller email raw
 794                        " -- "${cur##--pretty=}"))
 795                return
 796                ;;
 797        --*)
 798                COMPREPLY=($(compgen -W "--pretty=" -- "$cur"))
 799                return
 800                ;;
 801        esac
 802        __git_complete_file
 803}
 804
 805_git ()
 806{
 807        local i c=1 command __git_dir
 808
 809        while [ $c -lt $COMP_CWORD ]; do
 810                i="${COMP_WORDS[c]}"
 811                case "$i" in
 812                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
 813                --bare)      __git_dir="." ;;
 814                --version|--help|-p|--paginate) ;;
 815                *) command="$i"; break ;;
 816                esac
 817                c=$((++c))
 818        done
 819
 820        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
 821                case "${COMP_WORDS[COMP_CWORD]}" in
 822                --*=*) COMPREPLY=() ;;
 823                --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
 824                *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
 825                esac
 826                return
 827        fi
 828
 829        local expansion=$(__git_aliased_command "$command")
 830        [ "$expansion" ] && command="$expansion"
 831
 832        case "$command" in
 833        am)          _git_am ;;
 834        add)         _git_add ;;
 835        apply)       _git_apply ;;
 836        branch)      _git_branch ;;
 837        checkout)    _git_checkout ;;
 838        cherry-pick) _git_cherry_pick ;;
 839        commit)      _git_commit ;;
 840        config)      _git_config ;;
 841        diff)        _git_diff ;;
 842        diff-tree)   _git_diff_tree ;;
 843        fetch)       _git_fetch ;;
 844        format-patch) _git_format_patch ;;
 845        log)         _git_log ;;
 846        ls-remote)   _git_ls_remote ;;
 847        ls-tree)     _git_ls_tree ;;
 848        merge)       _git_merge;;
 849        merge-base)  _git_merge_base ;;
 850        name-rev)    _git_name_rev ;;
 851        pull)        _git_pull ;;
 852        push)        _git_push ;;
 853        rebase)      _git_rebase ;;
 854        reset)       _git_reset ;;
 855        show)        _git_show ;;
 856        show-branch) _git_log ;;
 857        whatchanged) _git_log ;;
 858        *)           COMPREPLY=() ;;
 859        esac
 860}
 861
 862_gitk ()
 863{
 864        local cur="${COMP_WORDS[COMP_CWORD]}"
 865        COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
 866}
 867
 868complete -o default -o nospace -F _git git
 869complete -o default            -F _gitk gitk
 870complete -o default            -F _git_am git-am
 871complete -o default            -F _git_apply git-apply
 872complete -o default            -F _git_branch git-branch
 873complete -o default            -F _git_checkout git-checkout
 874complete -o default            -F _git_cherry_pick git-cherry-pick
 875complete -o default            -F _git_commit git-commit
 876complete -o default -o nospace -F _git_diff git-diff
 877complete -o default            -F _git_diff_tree git-diff-tree
 878complete -o default -o nospace -F _git_fetch git-fetch
 879complete -o default -o nospace -F _git_format_patch git-format-patch
 880complete -o default -o nospace -F _git_log git-log
 881complete -o default            -F _git_ls_remote git-ls-remote
 882complete -o default -o nospace -F _git_ls_tree git-ls-tree
 883complete -o default            -F _git_merge git-merge
 884complete -o default            -F _git_merge_base git-merge-base
 885complete -o default            -F _git_name_rev git-name-rev
 886complete -o default -o nospace -F _git_pull git-pull
 887complete -o default -o nospace -F _git_push git-push
 888complete -o default            -F _git_rebase git-rebase
 889complete -o default            -F _git_config git-config
 890complete -o default            -F _git_reset git-reset
 891complete -o default -o nospace -F _git_show git-show
 892complete -o default -o nospace -F _git_log git-show-branch
 893complete -o default -o nospace -F _git_log git-whatchanged
 894
 895# The following are necessary only for Cygwin, and only are needed
 896# when the user has tab-completed the executable name and consequently
 897# included the '.exe' suffix.
 898#
 899if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
 900complete -o default            -F _git_add git-add.exe
 901complete -o default            -F _git_apply git-apply.exe
 902complete -o default -o nospace -F _git git.exe
 903complete -o default            -F _git_branch git-branch.exe
 904complete -o default -o nospace -F _git_diff git-diff.exe
 905complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
 906complete -o default -o nospace -F _git_format_patch git-format-patch.exe
 907complete -o default -o nospace -F _git_log git-log.exe
 908complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 909complete -o default            -F _git_merge_base git-merge-base.exe
 910complete -o default            -F _git_name_rev git-name-rev.exe
 911complete -o default -o nospace -F _git_push git-push.exe
 912complete -o default            -F _git_config git-config
 913complete -o default -o nospace -F _git_show git-show.exe
 914complete -o default -o nospace -F _git_log git-show-branch.exe
 915complete -o default -o nospace -F _git_log git-whatchanged.exe
 916fi