1cf576e1e57820ed13bfa9fe583b77779b315502
   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                cat-file)         : plumbing;;
 254                check-ref-format) : plumbing;;
 255                commit-tree)      : plumbing;;
 256                convert-objects)  : plumbing;;
 257                cvsserver)        : daemon;;
 258                daemon)           : daemon;;
 259                fetch-pack)       : plumbing;;
 260                hash-object)      : plumbing;;
 261                http-*)           : transport;;
 262                index-pack)       : plumbing;;
 263                local-fetch)      : plumbing;;
 264                mailinfo)         : plumbing;;
 265                mailsplit)        : plumbing;;
 266                merge-*)          : plumbing;;
 267                mktree)           : plumbing;;
 268                mktag)            : plumbing;;
 269                pack-objects)     : plumbing;;
 270                pack-redundant)   : plumbing;;
 271                pack-refs)        : plumbing;;
 272                parse-remote)     : plumbing;;
 273                patch-id)         : plumbing;;
 274                peek-remote)      : plumbing;;
 275                read-tree)        : plumbing;;
 276                receive-pack)     : plumbing;;
 277                reflog)           : plumbing;;
 278                rerere)           : plumbing;;
 279                rev-list)         : plumbing;;
 280                rev-parse)        : plumbing;;
 281                runstatus)        : plumbing;;
 282                sh-setup)         : internal;;
 283                shell)            : daemon;;
 284                send-pack)        : plumbing;;
 285                show-index)       : plumbing;;
 286                ssh-*)            : transport;;
 287                stripspace)       : plumbing;;
 288                symbolic-ref)     : plumbing;;
 289                unpack-file)      : plumbing;;
 290                unpack-objects)   : plumbing;;
 291                update-ref)       : plumbing;;
 292                update-server-info) : daemon;;
 293                upload-archive)   : plumbing;;
 294                upload-pack)      : plumbing;;
 295                write-tree)       : plumbing;;
 296                *) echo $i;;
 297                esac
 298        done
 299}
 300__git_commandlist=
 301__git_commandlist="$(__git_commands 2>/dev/null)"
 302
 303__git_aliases ()
 304{
 305        local i IFS=$'\n'
 306        for i in $(git --git-dir="$(__gitdir)" config --list); do
 307                case "$i" in
 308                alias.*)
 309                        i="${i#alias.}"
 310                        echo "${i/=*/}"
 311                        ;;
 312                esac
 313        done
 314}
 315
 316__git_aliased_command ()
 317{
 318        local word cmdline=$(git --git-dir="$(__gitdir)" \
 319                config --get "alias.$1")
 320        for word in $cmdline; do
 321                if [ "${word##-*}" ]; then
 322                        echo $word
 323                        return
 324                fi
 325        done
 326}
 327
 328__git_whitespacelist="nowarn warn error error-all strip"
 329
 330_git_am ()
 331{
 332        local cur="${COMP_WORDS[COMP_CWORD]}"
 333        if [ -d .dotest ]; then
 334                COMPREPLY=($(compgen -W "
 335                        --skip --resolved
 336                        " -- "$cur"))
 337                return
 338        fi
 339        case "$cur" in
 340        --whitespace=*)
 341                COMPREPLY=($(compgen -W "$__git_whitespacelist" \
 342                        -- "${cur##--whitespace=}"))
 343                return
 344                ;;
 345        --*)
 346                COMPREPLY=($(compgen -W "
 347                        --signoff --utf8 --binary --3way --interactive
 348                        --whitespace=
 349                        " -- "$cur"))
 350                return
 351        esac
 352        COMPREPLY=()
 353}
 354
 355_git_apply ()
 356{
 357        local cur="${COMP_WORDS[COMP_CWORD]}"
 358        case "$cur" in
 359        --whitespace=*)
 360                COMPREPLY=($(compgen -W "$__git_whitespacelist" \
 361                        -- "${cur##--whitespace=}"))
 362                return
 363                ;;
 364        --*)
 365                COMPREPLY=($(compgen -W "
 366                        --stat --numstat --summary --check --index
 367                        --cached --index-info --reverse --reject --unidiff-zero
 368                        --apply --no-add --exclude=
 369                        --whitespace= --inaccurate-eof --verbose
 370                        " -- "$cur"))
 371                return
 372        esac
 373        COMPREPLY=()
 374}
 375
 376_git_add ()
 377{
 378        local cur="${COMP_WORDS[COMP_CWORD]}"
 379        case "$cur" in
 380        --*)
 381                COMPREPLY=($(compgen -W "
 382                        --interactive
 383                        " -- "$cur"))
 384                return
 385        esac
 386        COMPREPLY=()
 387}
 388
 389_git_branch ()
 390{
 391        local cur="${COMP_WORDS[COMP_CWORD]}"
 392        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 393}
 394
 395_git_checkout ()
 396{
 397        local cur="${COMP_WORDS[COMP_CWORD]}"
 398        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 399}
 400
 401_git_cherry_pick ()
 402{
 403        local cur="${COMP_WORDS[COMP_CWORD]}"
 404        case "$cur" in
 405        --*)
 406                COMPREPLY=($(compgen -W "
 407                        --edit --no-commit
 408                        " -- "$cur"))
 409                ;;
 410        *)
 411                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 412                ;;
 413        esac
 414}
 415
 416_git_commit ()
 417{
 418        local cur="${COMP_WORDS[COMP_CWORD]}"
 419        case "$cur" in
 420        --*)
 421                COMPREPLY=($(compgen -W "
 422                        --all --author= --signoff --verify --no-verify
 423                        --edit --amend --include --only
 424                        " -- "$cur"))
 425                return
 426        esac
 427        COMPREPLY=()
 428}
 429
 430_git_diff ()
 431{
 432        __git_complete_file
 433}
 434
 435_git_diff_tree ()
 436{
 437        local cur="${COMP_WORDS[COMP_CWORD]}"
 438        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 439}
 440
 441_git_fetch ()
 442{
 443        local cur="${COMP_WORDS[COMP_CWORD]}"
 444
 445        case "${COMP_WORDS[0]},$COMP_CWORD" in
 446        git-fetch*,1)
 447                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 448                ;;
 449        git,2)
 450                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 451                ;;
 452        *)
 453                case "$cur" in
 454                *:*)
 455                        cur="${cur#*:}"
 456                        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 457                        ;;
 458                *)
 459                        local remote
 460                        case "${COMP_WORDS[0]}" in
 461                        git-fetch) remote="${COMP_WORDS[1]}" ;;
 462                        git)       remote="${COMP_WORDS[2]}" ;;
 463                        esac
 464                        COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
 465                        ;;
 466                esac
 467                ;;
 468        esac
 469}
 470
 471_git_format_patch ()
 472{
 473        local cur="${COMP_WORDS[COMP_CWORD]}"
 474        case "$cur" in
 475        --*)
 476                COMPREPLY=($(compgen -W "
 477                        --stdout --attach --thread
 478                        --output-directory
 479                        --numbered --start-number
 480                        --keep-subject
 481                        --signoff
 482                        --in-reply-to=
 483                        --full-index --binary
 484                        " -- "$cur"))
 485                return
 486                ;;
 487        esac
 488        __git_complete_revlist
 489}
 490
 491_git_ls_remote ()
 492{
 493        local cur="${COMP_WORDS[COMP_CWORD]}"
 494        COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 495}
 496
 497_git_ls_tree ()
 498{
 499        __git_complete_file
 500}
 501
 502_git_log ()
 503{
 504        local cur="${COMP_WORDS[COMP_CWORD]}"
 505        case "$cur" in
 506        --pretty=*)
 507                COMPREPLY=($(compgen -W "
 508                        oneline short medium full fuller email raw
 509                        " -- "${cur##--pretty=}"))
 510                return
 511                ;;
 512        --*)
 513                COMPREPLY=($(compgen -W "
 514                        --max-count= --max-age= --since= --after=
 515                        --min-age= --before= --until=
 516                        --root --not --topo-order --date-order
 517                        --no-merges
 518                        --abbrev-commit --abbrev=
 519                        --relative-date
 520                        --author= --committer= --grep=
 521                        --all-match
 522                        --pretty= --name-status --name-only
 523                        " -- "$cur"))
 524                return
 525                ;;
 526        esac
 527        __git_complete_revlist
 528}
 529
 530_git_merge ()
 531{
 532        local cur="${COMP_WORDS[COMP_CWORD]}"
 533        case "${COMP_WORDS[COMP_CWORD-1]}" in
 534        -s|--strategy)
 535                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 536                return
 537        esac
 538        case "$cur" in
 539        --strategy=*)
 540                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 541                        -- "${cur##--strategy=}"))
 542                return
 543                ;;
 544        --*)
 545                COMPREPLY=($(compgen -W "
 546                        --no-commit --no-summary --squash --strategy
 547                        " -- "$cur"))
 548                return
 549        esac
 550        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 551}
 552
 553_git_merge_base ()
 554{
 555        local cur="${COMP_WORDS[COMP_CWORD]}"
 556        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 557}
 558
 559_git_name_rev ()
 560{
 561        local cur="${COMP_WORDS[COMP_CWORD]}"
 562        COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
 563}
 564
 565_git_pull ()
 566{
 567        local cur="${COMP_WORDS[COMP_CWORD]}"
 568
 569        case "${COMP_WORDS[0]},$COMP_CWORD" in
 570        git-pull*,1)
 571                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 572                ;;
 573        git,2)
 574                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 575                ;;
 576        *)
 577                local remote
 578                case "${COMP_WORDS[0]}" in
 579                git-pull)  remote="${COMP_WORDS[1]}" ;;
 580                git)       remote="${COMP_WORDS[2]}" ;;
 581                esac
 582                COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 583                ;;
 584        esac
 585}
 586
 587_git_push ()
 588{
 589        local cur="${COMP_WORDS[COMP_CWORD]}"
 590
 591        case "${COMP_WORDS[0]},$COMP_CWORD" in
 592        git-push*,1)
 593                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 594                ;;
 595        git,2)
 596                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 597                ;;
 598        *)
 599                case "$cur" in
 600                *:*)
 601                        local remote
 602                        case "${COMP_WORDS[0]}" in
 603                        git-push)  remote="${COMP_WORDS[1]}" ;;
 604                        git)       remote="${COMP_WORDS[2]}" ;;
 605                        esac
 606                        cur="${cur#*:}"
 607                        COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 608                        ;;
 609                *)
 610                        COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
 611                        ;;
 612                esac
 613                ;;
 614        esac
 615}
 616
 617_git_rebase ()
 618{
 619        local cur="${COMP_WORDS[COMP_CWORD]}"
 620        if [ -d .dotest ]; then
 621                COMPREPLY=($(compgen -W "
 622                        --continue --skip --abort
 623                        " -- "$cur"))
 624                return
 625        fi
 626        case "${COMP_WORDS[COMP_CWORD-1]}" in
 627        -s|--strategy)
 628                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 629                return
 630        esac
 631        case "$cur" in
 632        --strategy=*)
 633                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 634                        -- "${cur##--strategy=}"))
 635                return
 636                ;;
 637        --*)
 638                COMPREPLY=($(compgen -W "
 639                        --onto --merge --strategy
 640                        " -- "$cur"))
 641                return
 642        esac
 643        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 644}
 645
 646_git_config ()
 647{
 648        local cur="${COMP_WORDS[COMP_CWORD]}"
 649        local prv="${COMP_WORDS[COMP_CWORD-1]}"
 650        case "$prv" in
 651        branch.*.remote)
 652                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 653                return
 654                ;;
 655        branch.*.merge)
 656                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 657                return
 658                ;;
 659        remote.*.fetch)
 660                local remote="${prv#remote.}"
 661                remote="${remote%.fetch}"
 662                COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
 663                        -- "$cur"))
 664                return
 665                ;;
 666        remote.*.push)
 667                local remote="${prv#remote.}"
 668                remote="${remote%.push}"
 669                COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
 670                        for-each-ref --format='%(refname):%(refname)' \
 671                        refs/heads)" -- "$cur"))
 672                return
 673                ;;
 674        *.*)
 675                COMPREPLY=()
 676                return
 677                ;;
 678        esac
 679        case "$cur" in
 680        --*)
 681                COMPREPLY=($(compgen -W "
 682                        --global --list --replace-all
 683                        --get --get-all --get-regexp
 684                        --unset --unset-all
 685                        " -- "$cur"))
 686                return
 687                ;;
 688        branch.*.*)
 689                local pfx="${cur%.*}."
 690                cur="${cur##*.}"
 691                COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
 692                return
 693                ;;
 694        branch.*)
 695                local pfx="${cur%.*}."
 696                cur="${cur#*.}"
 697                COMPREPLY=($(compgen -P "$pfx" -S . \
 698                        -W "$(__git_heads)" -- "$cur"))
 699                return
 700                ;;
 701        remote.*.*)
 702                local pfx="${cur%.*}."
 703                cur="${cur##*.}"
 704                COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
 705                return
 706                ;;
 707        remote.*)
 708                local pfx="${cur%.*}."
 709                cur="${cur#*.}"
 710                COMPREPLY=($(compgen -P "$pfx" -S . \
 711                        -W "$(__git_remotes)" -- "$cur"))
 712                return
 713                ;;
 714        esac
 715        COMPREPLY=($(compgen -W "
 716                apply.whitespace
 717                core.fileMode
 718                core.gitProxy
 719                core.ignoreStat
 720                core.preferSymlinkRefs
 721                core.logAllRefUpdates
 722                core.repositoryFormatVersion
 723                core.sharedRepository
 724                core.warnAmbiguousRefs
 725                core.compression
 726                core.legacyHeaders
 727                i18n.commitEncoding
 728                i18n.logOutputEncoding
 729                diff.color
 730                color.diff
 731                diff.renameLimit
 732                diff.renames
 733                pager.color
 734                color.pager
 735                status.color
 736                color.status
 737                log.showroot
 738                show.difftree
 739                showbranch.default
 740                whatchanged.difftree
 741                http.sslVerify
 742                http.sslCert
 743                http.sslKey
 744                http.sslCAInfo
 745                http.sslCAPath
 746                http.maxRequests
 747                http.lowSpeedLimit http.lowSpeedTime
 748                http.noEPSV
 749                pack.window
 750                repack.useDeltaBaseOffset
 751                pull.octopus pull.twohead
 752                merge.summary
 753                receive.unpackLimit
 754                receive.denyNonFastForwards
 755                user.name user.email
 756                tar.umask
 757                gitcvs.enabled
 758                gitcvs.logfile
 759                branch. remote.
 760        " -- "$cur"))
 761}
 762
 763_git_reset ()
 764{
 765        local cur="${COMP_WORDS[COMP_CWORD]}"
 766        local opt="--mixed --hard --soft"
 767        COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
 768}
 769
 770_git_show ()
 771{
 772        local cur="${COMP_WORDS[COMP_CWORD]}"
 773        case "$cur" in
 774        --pretty=*)
 775                COMPREPLY=($(compgen -W "
 776                        oneline short medium full fuller email raw
 777                        " -- "${cur##--pretty=}"))
 778                return
 779                ;;
 780        --*)
 781                COMPREPLY=($(compgen -W "--pretty=" -- "$cur"))
 782                return
 783                ;;
 784        esac
 785        __git_complete_file
 786}
 787
 788_git ()
 789{
 790        local i c=1 command __git_dir
 791
 792        while [ $c -lt $COMP_CWORD ]; do
 793                i="${COMP_WORDS[c]}"
 794                case "$i" in
 795                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
 796                --bare)      __git_dir="." ;;
 797                --version|--help|-p|--paginate) ;;
 798                *) command="$i"; break ;;
 799                esac
 800                c=$((++c))
 801        done
 802
 803        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
 804                case "${COMP_WORDS[COMP_CWORD]}" in
 805                --*=*) COMPREPLY=() ;;
 806                --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
 807                *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
 808                esac
 809                return
 810        fi
 811
 812        local expansion=$(__git_aliased_command "$command")
 813        [ "$expansion" ] && command="$expansion"
 814
 815        case "$command" in
 816        am)          _git_am ;;
 817        add)         _git_add ;;
 818        apply)       _git_apply ;;
 819        branch)      _git_branch ;;
 820        checkout)    _git_checkout ;;
 821        cherry-pick) _git_cherry_pick ;;
 822        commit)      _git_commit ;;
 823        config)      _git_config ;;
 824        diff)        _git_diff ;;
 825        diff-tree)   _git_diff_tree ;;
 826        fetch)       _git_fetch ;;
 827        format-patch) _git_format_patch ;;
 828        log)         _git_log ;;
 829        ls-remote)   _git_ls_remote ;;
 830        ls-tree)     _git_ls_tree ;;
 831        merge)       _git_merge;;
 832        merge-base)  _git_merge_base ;;
 833        name-rev)    _git_name_rev ;;
 834        pull)        _git_pull ;;
 835        push)        _git_push ;;
 836        rebase)      _git_rebase ;;
 837        repo-config) _git_config ;;
 838        reset)       _git_reset ;;
 839        show)        _git_show ;;
 840        show-branch) _git_log ;;
 841        whatchanged) _git_log ;;
 842        *)           COMPREPLY=() ;;
 843        esac
 844}
 845
 846_gitk ()
 847{
 848        local cur="${COMP_WORDS[COMP_CWORD]}"
 849        COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
 850}
 851
 852complete -o default -o nospace -F _git git
 853complete -o default            -F _gitk gitk
 854complete -o default            -F _git_am git-am
 855complete -o default            -F _git_apply git-apply
 856complete -o default            -F _git_branch git-branch
 857complete -o default            -F _git_checkout git-checkout
 858complete -o default            -F _git_cherry_pick git-cherry-pick
 859complete -o default            -F _git_commit git-commit
 860complete -o default -o nospace -F _git_diff git-diff
 861complete -o default            -F _git_diff_tree git-diff-tree
 862complete -o default -o nospace -F _git_fetch git-fetch
 863complete -o default -o nospace -F _git_format_patch git-format-patch
 864complete -o default -o nospace -F _git_log git-log
 865complete -o default            -F _git_ls_remote git-ls-remote
 866complete -o default -o nospace -F _git_ls_tree git-ls-tree
 867complete -o default            -F _git_merge git-merge
 868complete -o default            -F _git_merge_base git-merge-base
 869complete -o default            -F _git_name_rev git-name-rev
 870complete -o default -o nospace -F _git_pull git-pull
 871complete -o default -o nospace -F _git_push git-push
 872complete -o default            -F _git_rebase git-rebase
 873complete -o default            -F _git_config git-config
 874complete -o default            -F _git_reset git-reset
 875complete -o default -o nospace -F _git_show git-show
 876complete -o default -o nospace -F _git_log git-show-branch
 877complete -o default -o nospace -F _git_log git-whatchanged
 878
 879# The following are necessary only for Cygwin, and only are needed
 880# when the user has tab-completed the executable name and consequently
 881# included the '.exe' suffix.
 882#
 883if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
 884complete -o default            -F _git_add git-add.exe
 885complete -o default            -F _git_apply git-apply.exe
 886complete -o default -o nospace -F _git git.exe
 887complete -o default            -F _git_branch git-branch.exe
 888complete -o default -o nospace -F _git_diff git-diff.exe
 889complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
 890complete -o default -o nospace -F _git_format_patch git-format-patch.exe
 891complete -o default -o nospace -F _git_log git-log.exe
 892complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 893complete -o default            -F _git_merge_base git-merge-base.exe
 894complete -o default            -F _git_name_rev git-name-rev.exe
 895complete -o default -o nospace -F _git_push git-push.exe
 896complete -o default            -F _git_config git-config
 897complete -o default -o nospace -F _git_show git-show.exe
 898complete -o default -o nospace -F _git_log git-show-branch.exe
 899complete -o default -o nospace -F _git_log git-whatchanged.exe
 900fi