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