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