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