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