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