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