902f80b937fed7581fed1d967dde130411b13fb1
   1#
   2# bash completion support for core Git.
   3#
   4# Copyright (C) 2006 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        echo "${__git_dir:-$(git rev-parse --git-dir 2>/dev/null)}"
  38}
  39
  40__git_ps1 ()
  41{
  42        local b="$(git symbolic-ref HEAD 2>/dev/null)"
  43        if [ -n "$b" ]; then
  44                if [ -n "$1" ]; then
  45                        printf "$1" "${b##refs/heads/}"
  46                else
  47                        printf " (%s)" "${b##refs/heads/}"
  48                fi
  49        fi
  50}
  51
  52__git_heads ()
  53{
  54        local cmd i is_hash=y dir="${1:-$(__gitdir)}"
  55        if [ -d "$dir" ]; then
  56                for i in $(git --git-dir="$dir" \
  57                        for-each-ref --format='%(refname)' \
  58                        refs/heads ); do
  59                        echo "${i#refs/heads/}"
  60                done
  61                return
  62        fi
  63        for i in $(git-ls-remote "$dir" 2>/dev/null); do
  64                case "$is_hash,$i" in
  65                y,*) is_hash=n ;;
  66                n,*^{}) is_hash=y ;;
  67                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  68                n,*) is_hash=y; echo "$i" ;;
  69                esac
  70        done
  71}
  72
  73__git_refs ()
  74{
  75        local cmd i is_hash=y dir="${1:-$(__gitdir)}"
  76        if [ -d "$dir" ]; then
  77                if [ -e "$dir/HEAD" ]; then echo HEAD; fi
  78                for i in $(git --git-dir="$dir" \
  79                        for-each-ref --format='%(refname)' \
  80                        refs/tags refs/heads refs/remotes); do
  81                        case "$i" in
  82                                refs/tags/*)    echo "${i#refs/tags/}" ;;
  83                                refs/heads/*)   echo "${i#refs/heads/}" ;;
  84                                refs/remotes/*) echo "${i#refs/remotes/}" ;;
  85                                *)              echo "$i" ;;
  86                        esac
  87                done
  88                return
  89        fi
  90        for i in $(git-ls-remote "$dir" 2>/dev/null); do
  91                case "$is_hash,$i" in
  92                y,*) is_hash=n ;;
  93                n,*^{}) is_hash=y ;;
  94                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
  95                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
  96                n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
  97                n,*) is_hash=y; echo "$i" ;;
  98                esac
  99        done
 100}
 101
 102__git_refs2 ()
 103{
 104        local cmd i is_hash=y dir="${1:-$(__gitdir)}"
 105        if [ -d "$dir" ]; then
 106                cmd=git-peek-remote
 107        else
 108                cmd=git-ls-remote
 109        fi
 110        for i in $($cmd "$dir" 2>/dev/null); do
 111                case "$is_hash,$i" in
 112                y,*) is_hash=n ;;
 113                n,*^{}) is_hash=y ;;
 114                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}:${i#refs/tags/}" ;;
 115                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}:${i#refs/heads/}" ;;
 116                n,*) is_hash=y; echo "$i:$i" ;;
 117                esac
 118        done
 119}
 120
 121__git_refs_remotes ()
 122{
 123        local cmd i is_hash=y
 124        for i in $(git-ls-remote "$1" 2>/dev/null); do
 125                case "$is_hash,$i" in
 126                n,refs/heads/*)
 127                        is_hash=y
 128                        echo "$i:refs/remotes/$1/${i#refs/heads/}"
 129                        ;;
 130                y,*) is_hash=n ;;
 131                n,*^{}) is_hash=y ;;
 132                n,refs/tags/*) is_hash=y;;
 133                n,*) is_hash=y; ;;
 134                esac
 135        done
 136}
 137
 138__git_remotes ()
 139{
 140        local i ngoff IFS=$'\n' d="$(__gitdir)"
 141        shopt -q nullglob || ngoff=1
 142        shopt -s nullglob
 143        for i in "$d/remotes"/*; do
 144                echo ${i#$d/remotes/}
 145        done
 146        [ "$ngoff" ] && shopt -u nullglob
 147        for i in $(git --git-dir="$d" repo-config --list); do
 148                case "$i" in
 149                remote.*.url=*)
 150                        i="${i#remote.}"
 151                        echo "${i/.url=*/}"
 152                        ;;
 153                esac
 154        done
 155}
 156
 157__git_merge_strategies ()
 158{
 159        if [ -n "$__git_merge_strategylist" ]; then
 160                echo "$__git_merge_strategylist"
 161                return
 162        fi
 163        sed -n "/^all_strategies='/{
 164                s/^all_strategies='//
 165                s/'//
 166                p
 167                q
 168                }" "$(git --exec-path)/git-merge"
 169}
 170__git_merge_strategylist=
 171__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
 172
 173__git_complete_file ()
 174{
 175        local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
 176        case "$cur" in
 177        ?*:*)
 178                ref="${cur%%:*}"
 179                cur="${cur#*:}"
 180                case "$cur" in
 181                ?*/*)
 182                        pfx="${cur%/*}"
 183                        cur="${cur##*/}"
 184                        ls="$ref:$pfx"
 185                        pfx="$pfx/"
 186                        ;;
 187                *)
 188                        ls="$ref"
 189                        ;;
 190            esac
 191                COMPREPLY=($(compgen -P "$pfx" \
 192                        -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 193                                | sed '/^100... blob /s,^.*     ,,
 194                                       /^040000 tree /{
 195                                           s,^.*        ,,
 196                                           s,$,/,
 197                                       }
 198                                       s/^.*    //')" \
 199                        -- "$cur"))
 200                ;;
 201        *)
 202                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 203                ;;
 204        esac
 205}
 206
 207__git_complete_revlist ()
 208{
 209        local pfx cur="${COMP_WORDS[COMP_CWORD]}"
 210        case "$cur" in
 211        *...*)
 212                pfx="${cur%...*}..."
 213                cur="${cur#*...}"
 214                COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
 215                ;;
 216        *..*)
 217                pfx="${cur%..*}.."
 218                cur="${cur#*..}"
 219                COMPREPLY=($(compgen -P "$pfx" -W "$(__git_refs)" -- "$cur"))
 220                ;;
 221        *)
 222                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 223                ;;
 224        esac
 225}
 226
 227__git_commands ()
 228{
 229        if [ -n "$__git_commandlist" ]; then
 230                echo "$__git_commandlist"
 231                return
 232        fi
 233        local i IFS=" "$'\n'
 234        for i in $(git help -a|egrep '^ ')
 235        do
 236                case $i in
 237                check-ref-format) : plumbing;;
 238                commit-tree)      : plumbing;;
 239                convert-objects)  : plumbing;;
 240                cvsserver)        : daemon;;
 241                daemon)           : daemon;;
 242                fetch-pack)       : plumbing;;
 243                hash-object)      : plumbing;;
 244                http-*)           : transport;;
 245                index-pack)       : plumbing;;
 246                local-fetch)      : plumbing;;
 247                mailinfo)         : plumbing;;
 248                mailsplit)        : plumbing;;
 249                merge-*)          : plumbing;;
 250                mktree)           : plumbing;;
 251                mktag)            : plumbing;;
 252                pack-objects)     : plumbing;;
 253                pack-redundant)   : plumbing;;
 254                pack-refs)        : plumbing;;
 255                parse-remote)     : plumbing;;
 256                patch-id)         : plumbing;;
 257                peek-remote)      : plumbing;;
 258                read-tree)        : plumbing;;
 259                receive-pack)     : plumbing;;
 260                rerere)           : plumbing;;
 261                rev-list)         : plumbing;;
 262                rev-parse)        : plumbing;;
 263                runstatus)        : plumbing;;
 264                sh-setup)         : internal;;
 265                shell)            : daemon;;
 266                send-pack)        : plumbing;;
 267                show-index)       : plumbing;;
 268                ssh-*)            : transport;;
 269                stripspace)       : plumbing;;
 270                symbolic-ref)     : plumbing;;
 271                unpack-file)      : plumbing;;
 272                unpack-objects)   : plumbing;;
 273                update-ref)       : plumbing;;
 274                update-server-info) : daemon;;
 275                upload-archive)   : plumbing;;
 276                upload-pack)      : plumbing;;
 277                write-tree)       : plumbing;;
 278                *) echo $i;;
 279                esac
 280        done
 281}
 282__git_commandlist=
 283__git_commandlist="$(__git_commands 2>/dev/null)"
 284
 285__git_aliases ()
 286{
 287        local i IFS=$'\n'
 288        for i in $(git --git-dir="$(__gitdir)" repo-config --list); do
 289                case "$i" in
 290                alias.*)
 291                        i="${i#alias.}"
 292                        echo "${i/=*/}"
 293                        ;;
 294                esac
 295        done
 296}
 297
 298__git_aliased_command ()
 299{
 300        local word cmdline=$(git --git-dir="$(__gitdir)" \
 301                repo-config --get "alias.$1")
 302        for word in $cmdline; do
 303                if [ "${word##-*}" ]; then
 304                        echo $word
 305                        return
 306                fi
 307        done
 308}
 309
 310_git_branch ()
 311{
 312        local cur="${COMP_WORDS[COMP_CWORD]}"
 313        COMPREPLY=($(compgen -W "-l -f -d -D $(__git_refs)" -- "$cur"))
 314}
 315
 316_git_cat_file ()
 317{
 318        local cur="${COMP_WORDS[COMP_CWORD]}"
 319        case "${COMP_WORDS[0]},$COMP_CWORD" in
 320        git-cat-file*,1)
 321                COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
 322                ;;
 323        git,2)
 324                COMPREPLY=($(compgen -W "-p -t blob tree commit tag" -- "$cur"))
 325                ;;
 326        *)
 327                __git_complete_file
 328                ;;
 329        esac
 330}
 331
 332_git_checkout ()
 333{
 334        local cur="${COMP_WORDS[COMP_CWORD]}"
 335        COMPREPLY=($(compgen -W "-l -b $(__git_refs)" -- "$cur"))
 336}
 337
 338_git_cherry_pick ()
 339{
 340        local cur="${COMP_WORDS[COMP_CWORD]}"
 341        case "$cur" in
 342        --*)
 343                COMPREPLY=($(compgen -W "
 344                        --edit --no-commit
 345                        " -- "$cur"))
 346                ;;
 347        *)
 348                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 349                ;;
 350        esac
 351}
 352
 353_git_diff ()
 354{
 355        __git_complete_file
 356}
 357
 358_git_diff_tree ()
 359{
 360        local cur="${COMP_WORDS[COMP_CWORD]}"
 361        COMPREPLY=($(compgen -W "-r -p -M $(__git_refs)" -- "$cur"))
 362}
 363
 364_git_fetch ()
 365{
 366        local cur="${COMP_WORDS[COMP_CWORD]}"
 367
 368        case "${COMP_WORDS[0]},$COMP_CWORD" in
 369        git-fetch*,1)
 370                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 371                ;;
 372        git,2)
 373                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 374                ;;
 375        *)
 376                case "$cur" in
 377                *:*)
 378                        cur="${cur#*:}"
 379                        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 380                        ;;
 381                *)
 382                        local remote
 383                        case "${COMP_WORDS[0]}" in
 384                        git-fetch) remote="${COMP_WORDS[1]}" ;;
 385                        git)       remote="${COMP_WORDS[2]}" ;;
 386                        esac
 387                        COMPREPLY=($(compgen -W "$(__git_refs2 "$remote")" -- "$cur"))
 388                        ;;
 389                esac
 390                ;;
 391        esac
 392}
 393
 394_git_format_patch ()
 395{
 396        local cur="${COMP_WORDS[COMP_CWORD]}"
 397        case "$cur" in
 398        --*)
 399                COMPREPLY=($(compgen -W "
 400                        --stdout --attach --thread
 401                        --output-directory
 402                        --numbered --start-number
 403                        --keep-subject
 404                        --signoff
 405                        --in-reply-to=
 406                        --full-index --binary
 407                        " -- "$cur"))
 408                return
 409                ;;
 410        esac
 411        __git_complete_revlist
 412}
 413
 414_git_ls_remote ()
 415{
 416        local cur="${COMP_WORDS[COMP_CWORD]}"
 417        COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 418}
 419
 420_git_ls_tree ()
 421{
 422        __git_complete_file
 423}
 424
 425_git_log ()
 426{
 427        local cur="${COMP_WORDS[COMP_CWORD]}"
 428        case "$cur" in
 429        --pretty=*)
 430                COMPREPLY=($(compgen -W "
 431                        oneline short medium full fuller email raw
 432                        " -- "${cur##--pretty=}"))
 433                return
 434                ;;
 435        --*)
 436                COMPREPLY=($(compgen -W "
 437                        --max-count= --max-age= --since= --after=
 438                        --min-age= --before= --until=
 439                        --root --not --topo-order --date-order
 440                        --no-merges
 441                        --abbrev-commit --abbrev=
 442                        --relative-date
 443                        --author= --committer= --grep=
 444                        --all-match
 445                        --pretty= --name-status --name-only
 446                        " -- "$cur"))
 447                return
 448                ;;
 449        esac
 450        __git_complete_revlist
 451}
 452
 453_git_merge ()
 454{
 455        local cur="${COMP_WORDS[COMP_CWORD]}"
 456        case "${COMP_WORDS[COMP_CWORD-1]}" in
 457        -s|--strategy)
 458                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 459                return
 460        esac
 461        case "$cur" in
 462        --strategy=*)
 463                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 464                        -- "${cur##--strategy=}"))
 465                return
 466                ;;
 467        --*)
 468                COMPREPLY=($(compgen -W "
 469                        --no-commit --no-summary --squash --strategy
 470                        " -- "$cur"))
 471                return
 472        esac
 473        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 474}
 475
 476_git_merge_base ()
 477{
 478        local cur="${COMP_WORDS[COMP_CWORD]}"
 479        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 480}
 481
 482_git_name_rev ()
 483{
 484        local cur="${COMP_WORDS[COMP_CWORD]}"
 485        COMPREPLY=($(compgen -W "--tags --all --stdin" -- "$cur"))
 486}
 487
 488_git_pull ()
 489{
 490        local cur="${COMP_WORDS[COMP_CWORD]}"
 491
 492        case "${COMP_WORDS[0]},$COMP_CWORD" in
 493        git-pull*,1)
 494                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 495                ;;
 496        git,2)
 497                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 498                ;;
 499        *)
 500                local remote
 501                case "${COMP_WORDS[0]}" in
 502                git-pull)  remote="${COMP_WORDS[1]}" ;;
 503                git)       remote="${COMP_WORDS[2]}" ;;
 504                esac
 505                COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 506                ;;
 507        esac
 508}
 509
 510_git_push ()
 511{
 512        local cur="${COMP_WORDS[COMP_CWORD]}"
 513
 514        case "${COMP_WORDS[0]},$COMP_CWORD" in
 515        git-push*,1)
 516                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 517                ;;
 518        git,2)
 519                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 520                ;;
 521        *)
 522                case "$cur" in
 523                *:*)
 524                        local remote
 525                        case "${COMP_WORDS[0]}" in
 526                        git-push)  remote="${COMP_WORDS[1]}" ;;
 527                        git)       remote="${COMP_WORDS[2]}" ;;
 528                        esac
 529                        cur="${cur#*:}"
 530                        COMPREPLY=($(compgen -W "$(__git_refs "$remote")" -- "$cur"))
 531                        ;;
 532                *)
 533                        COMPREPLY=($(compgen -W "$(__git_refs2)" -- "$cur"))
 534                        ;;
 535                esac
 536                ;;
 537        esac
 538}
 539
 540_git_rebase ()
 541{
 542        local cur="${COMP_WORDS[COMP_CWORD]}"
 543        if [ -d .dotest ]; then
 544                COMPREPLY=($(compgen -W "
 545                        --continue --skip --abort
 546                        " -- "$cur"))
 547                return
 548        fi
 549        case "${COMP_WORDS[COMP_CWORD-1]}" in
 550        -s|--strategy)
 551                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" -- "$cur"))
 552                return
 553        esac
 554        case "$cur" in
 555        --strategy=*)
 556                COMPREPLY=($(compgen -W "$(__git_merge_strategies)" \
 557                        -- "${cur##--strategy=}"))
 558                return
 559                ;;
 560        --*)
 561                COMPREPLY=($(compgen -W "
 562                        --onto --merge --strategy
 563                        " -- "$cur"))
 564                return
 565        esac
 566        COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 567}
 568
 569_git_repo_config ()
 570{
 571        local cur="${COMP_WORDS[COMP_CWORD]}"
 572        local prv="${COMP_WORDS[COMP_CWORD-1]}"
 573        case "$prv" in
 574        branch.*.remote)
 575                COMPREPLY=($(compgen -W "$(__git_remotes)" -- "$cur"))
 576                return
 577                ;;
 578        branch.*.merge)
 579                COMPREPLY=($(compgen -W "$(__git_refs)" -- "$cur"))
 580                return
 581                ;;
 582        remote.*.fetch)
 583                local remote="${prv#remote.}"
 584                remote="${remote%.fetch}"
 585                COMPREPLY=($(compgen -W "$(__git_refs_remotes "$remote")" \
 586                        -- "$cur"))
 587                return
 588                ;;
 589        remote.*.push)
 590                local remote="${prv#remote.}"
 591                remote="${remote%.push}"
 592                COMPREPLY=($(compgen -W "$(git --git-dir="$(__gitdir)" \
 593                        for-each-ref --format='%(refname):%(refname)' \
 594                        refs/heads)" -- "$cur"))
 595                return
 596                ;;
 597        *.*)
 598                COMPREPLY=()
 599                return
 600                ;;
 601        esac
 602        case "$cur" in
 603        --*)
 604                COMPREPLY=($(compgen -W "
 605                        --global --list --replace-all
 606                        --get --get-all --get-regexp
 607                        --unset --unset-all
 608                        " -- "$cur"))
 609                return
 610                ;;
 611        branch.*.*)
 612                local pfx="${cur%.*}."
 613                cur="${cur##*.}"
 614                COMPREPLY=($(compgen -P "$pfx" -W "remote merge" -- "$cur"))
 615                return
 616                ;;
 617        branch.*)
 618                local pfx="${cur%.*}."
 619                cur="${cur#*.}"
 620                COMPREPLY=($(compgen -P "$pfx" -S . \
 621                        -W "$(__git_heads)" -- "$cur"))
 622                return
 623                ;;
 624        remote.*.*)
 625                local pfx="${cur%.*}."
 626                cur="${cur##*.}"
 627                COMPREPLY=($(compgen -P "$pfx" -W "url fetch push" -- "$cur"))
 628                return
 629                ;;
 630        remote.*)
 631                local pfx="${cur%.*}."
 632                cur="${cur#*.}"
 633                COMPREPLY=($(compgen -P "$pfx" -S . \
 634                        -W "$(__git_remotes)" -- "$cur"))
 635                return
 636                ;;
 637        esac
 638        COMPREPLY=($(compgen -W "
 639                apply.whitespace
 640                core.fileMode
 641                core.gitProxy
 642                core.ignoreStat
 643                core.preferSymlinkRefs
 644                core.logAllRefUpdates
 645                core.repositoryFormatVersion
 646                core.sharedRepository
 647                core.warnAmbiguousRefs
 648                core.compression
 649                core.legacyHeaders
 650                i18n.commitEncoding
 651                diff.color
 652                diff.renameLimit
 653                diff.renames
 654                pager.color
 655                status.color
 656                log.showroot
 657                show.difftree
 658                showbranch.default
 659                whatchanged.difftree
 660                http.sslVerify
 661                http.sslCert
 662                http.sslKey
 663                http.sslCAInfo
 664                http.sslCAPath
 665                http.maxRequests
 666                http.lowSpeedLimit http.lowSpeedTime
 667                http.noEPSV
 668                pack.window
 669                repack.useDeltaBaseOffset
 670                pull.octopus pull.twohead
 671                merge.summary
 672                receive.unpackLimit
 673                receive.denyNonFastForwards
 674                user.name user.email
 675                tar.umask
 676                gitcvs.enabled
 677                gitcvs.logfile
 678                branch. remote.
 679        " -- "$cur"))
 680}
 681
 682_git_reset ()
 683{
 684        local cur="${COMP_WORDS[COMP_CWORD]}"
 685        local opt="--mixed --hard --soft"
 686        COMPREPLY=($(compgen -W "$opt $(__git_refs)" -- "$cur"))
 687}
 688
 689_git ()
 690{
 691        local i c=1 command __git_dir
 692
 693        while [ $c -lt $COMP_CWORD ]; do
 694                i="${COMP_WORDS[c]}"
 695                case "$i" in
 696                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
 697                --bare)      __git_dir="." ;;
 698                --version|--help|-p|--paginate) ;;
 699                *) command="$i"; break ;;
 700                esac
 701                c=$((++c))
 702        done
 703
 704        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
 705                COMPREPLY=($(compgen -W "
 706                        --git-dir= --version --exec-path
 707                        $(__git_commands)
 708                        $(__git_aliases)
 709                        " -- "${COMP_WORDS[COMP_CWORD]}"))
 710                return;
 711        fi
 712
 713        local expansion=$(__git_aliased_command "$command")
 714        [ "$expansion" ] && command="$expansion"
 715
 716        case "$command" in
 717        branch)      _git_branch ;;
 718        cat-file)    _git_cat_file ;;
 719        checkout)    _git_checkout ;;
 720        cherry-pick) _git_cherry_pick ;;
 721        diff)        _git_diff ;;
 722        diff-tree)   _git_diff_tree ;;
 723        fetch)       _git_fetch ;;
 724        format-patch) _git_format_patch ;;
 725        log)         _git_log ;;
 726        ls-remote)   _git_ls_remote ;;
 727        ls-tree)     _git_ls_tree ;;
 728        merge)       _git_merge;;
 729        merge-base)  _git_merge_base ;;
 730        name-rev)    _git_name_rev ;;
 731        pull)        _git_pull ;;
 732        push)        _git_push ;;
 733        rebase)      _git_rebase ;;
 734        repo-config) _git_repo_config ;;
 735        reset)       _git_reset ;;
 736        show)        _git_log ;;
 737        show-branch) _git_log ;;
 738        whatchanged) _git_log ;;
 739        *)           COMPREPLY=() ;;
 740        esac
 741}
 742
 743_gitk ()
 744{
 745        local cur="${COMP_WORDS[COMP_CWORD]}"
 746        COMPREPLY=($(compgen -W "--all $(__git_refs)" -- "$cur"))
 747}
 748
 749complete -o default -o nospace -F _git git
 750complete -o default            -F _gitk gitk
 751complete -o default            -F _git_branch git-branch
 752complete -o default -o nospace -F _git_cat_file git-cat-file
 753complete -o default            -F _git_checkout git-checkout
 754complete -o default            -F _git_cherry_pick git-cherry-pick
 755complete -o default -o nospace -F _git_diff git-diff
 756complete -o default            -F _git_diff_tree git-diff-tree
 757complete -o default -o nospace -F _git_fetch git-fetch
 758complete -o default -o nospace -F _git_format_patch git-format-patch
 759complete -o default -o nospace -F _git_log git-log
 760complete -o default            -F _git_ls_remote git-ls-remote
 761complete -o default -o nospace -F _git_ls_tree git-ls-tree
 762complete -o default            -F _git_merge git-merge
 763complete -o default            -F _git_merge_base git-merge-base
 764complete -o default            -F _git_name_rev git-name-rev
 765complete -o default -o nospace -F _git_pull git-pull
 766complete -o default -o nospace -F _git_push git-push
 767complete -o default            -F _git_rebase git-rebase
 768complete -o default            -F _git_repo_config git-repo-config
 769complete -o default            -F _git_reset git-reset
 770complete -o default            -F _git_log git-show
 771complete -o default -o nospace -F _git_log git-show-branch
 772complete -o default -o nospace -F _git_log git-whatchanged
 773
 774# The following are necessary only for Cygwin, and only are needed
 775# when the user has tab-completed the executable name and consequently
 776# included the '.exe' suffix.
 777#
 778if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
 779complete -o default -o nospace -F _git git.exe
 780complete -o default            -F _git_branch git-branch.exe
 781complete -o default -o nospace -F _git_cat_file git-cat-file.exe
 782complete -o default -o nospace -F _git_diff git-diff.exe
 783complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
 784complete -o default -o nospace -F _git_format_patch git-format-patch.exe
 785complete -o default -o nospace -F _git_log git-log.exe
 786complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 787complete -o default            -F _git_merge_base git-merge-base.exe
 788complete -o default            -F _git_name_rev git-name-rev.exe
 789complete -o default -o nospace -F _git_push git-push.exe
 790complete -o default            -F _git_repo_config git-repo-config
 791complete -o default -o nospace -F _git_log git-show.exe
 792complete -o default -o nospace -F _git_log git-show-branch.exe
 793complete -o default -o nospace -F _git_log git-whatchanged.exe
 794fi