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