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