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