contrib / completion / git-completion.bashon commit Add bare repository indicator for __git_ps1 (f50edca)
   1#!bash
   2#
   3# bash completion support for core Git.
   4#
   5# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
   6# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
   7# Distributed under the GNU General Public License, version 2.0.
   8#
   9# The contained completion routines provide support for completing:
  10#
  11#    *) local and remote branch names
  12#    *) local and remote tag names
  13#    *) .git/remotes file names
  14#    *) git 'subcommands'
  15#    *) tree paths within 'ref:path/to/file' expressions
  16#    *) common --long-options
  17#
  18# To use these routines:
  19#
  20#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  21#    2) Added the following line to your .bashrc:
  22#        source ~/.git-completion.sh
  23#
  24#    3) You may want to make sure the git executable is available
  25#       in your PATH before this script is sourced, as some caching
  26#       is performed while the script loads.  If git isn't found
  27#       at source time then all lookups will be done on demand,
  28#       which may be slightly slower.
  29#
  30#    4) Consider changing your PS1 to also show the current branch:
  31#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  32#
  33#       The argument to __git_ps1 will be displayed only if you
  34#       are currently in a git repository.  The %s token will be
  35#       the name of the current branch.
  36#
  37#       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
  38#       value, unstaged (*) and staged (+) changes will be shown next
  39#       to the branch name.  You can configure this per-repository
  40#       with the bash.showDirtyState variable, which defaults to true
  41#       once GIT_PS1_SHOWDIRTYSTATE is enabled.
  42#
  43# To submit patches:
  44#
  45#    *) Read Documentation/SubmittingPatches
  46#    *) Send all patches to the current maintainer:
  47#
  48#       "Shawn O. Pearce" <spearce@spearce.org>
  49#
  50#    *) Always CC the Git mailing list:
  51#
  52#       git@vger.kernel.org
  53#
  54
  55case "$COMP_WORDBREAKS" in
  56*:*) : great ;;
  57*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  58esac
  59
  60# __gitdir accepts 0 or 1 arguments (i.e., location)
  61# returns location of .git repo
  62__gitdir ()
  63{
  64        if [ -z "${1-}" ]; then
  65                if [ -n "${__git_dir-}" ]; then
  66                        echo "$__git_dir"
  67                elif [ -d .git ]; then
  68                        echo .git
  69                else
  70                        git rev-parse --git-dir 2>/dev/null
  71                fi
  72        elif [ -d "$1/.git" ]; then
  73                echo "$1/.git"
  74        else
  75                echo "$1"
  76        fi
  77}
  78
  79# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
  80# returns text to add to bash PS1 prompt (includes branch name)
  81__git_ps1 ()
  82{
  83        local g="$(__gitdir)"
  84        if [ -n "$g" ]; then
  85                local r
  86                local b
  87                if [ -d "$g/rebase-apply" ]; then
  88                        if [ -f "$g/rebase-apply/rebasing" ]; then
  89                                r="|REBASE"
  90                elif [ -f "$g/rebase-apply/applying" ]; then
  91                                r="|AM"
  92                        else
  93                                r="|AM/REBASE"
  94                        fi
  95                        b="$(git symbolic-ref HEAD 2>/dev/null)"
  96                elif [ -f "$g/rebase-merge/interactive" ]; then
  97                        r="|REBASE-i"
  98                        b="$(cat "$g/rebase-merge/head-name")"
  99                elif [ -d "$g/rebase-merge" ]; then
 100                        r="|REBASE-m"
 101                        b="$(cat "$g/rebase-merge/head-name")"
 102                elif [ -f "$g/MERGE_HEAD" ]; then
 103                        r="|MERGING"
 104                        b="$(git symbolic-ref HEAD 2>/dev/null)"
 105                else
 106                        if [ -f "$g/BISECT_LOG" ]; then
 107                                r="|BISECTING"
 108                        fi
 109                        if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
 110                                if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
 111                                        if [ -r "$g/HEAD" ]; then
 112                                                b="$(cut -c1-7 "$g/HEAD")..."
 113                                        fi
 114                                fi
 115                        fi
 116                fi
 117
 118                local w
 119                local i
 120
 121                if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
 122                        b="GIT_DIR!"
 123                elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
 124                        if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
 125                                if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
 126                                        git diff --no-ext-diff --ignore-submodules \
 127                                                --quiet --exit-code || w="*"
 128                                        if git rev-parse --quiet --verify HEAD >/dev/null; then
 129                                                git diff-index --cached --quiet \
 130                                                        --ignore-submodules HEAD -- || i="+"
 131                                        else
 132                                                i="#"
 133                                        fi
 134                                fi
 135                        fi
 136                fi
 137
 138                local c
 139
 140                if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
 141                        c="BARE:"
 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_all_commands ()
 392{
 393        if [ -n "${__git_all_commandlist-}" ]; then
 394                echo "$__git_all_commandlist"
 395                return
 396        fi
 397        local i IFS=" "$'\n'
 398        for i in $(git help -a|egrep '^ ')
 399        do
 400                case $i in
 401                *--*)             : helper pattern;;
 402                *) echo $i;;
 403                esac
 404        done
 405}
 406__git_all_commandlist=
 407__git_all_commandlist="$(__git_all_commands 2>/dev/null)"
 408
 409__git_porcelain_commands ()
 410{
 411        if [ -n "${__git_porcelain_commandlist-}" ]; then
 412                echo "$__git_porcelain_commandlist"
 413                return
 414        fi
 415        local i IFS=" "$'\n'
 416        for i in "help" $(__git_all_commands)
 417        do
 418                case $i in
 419                *--*)             : helper pattern;;
 420                applymbox)        : ask gittus;;
 421                applypatch)       : ask gittus;;
 422                archimport)       : import;;
 423                cat-file)         : plumbing;;
 424                check-attr)       : plumbing;;
 425                check-ref-format) : plumbing;;
 426                checkout-index)   : plumbing;;
 427                commit-tree)      : plumbing;;
 428                count-objects)    : infrequent;;
 429                cvsexportcommit)  : export;;
 430                cvsimport)        : import;;
 431                cvsserver)        : daemon;;
 432                daemon)           : daemon;;
 433                diff-files)       : plumbing;;
 434                diff-index)       : plumbing;;
 435                diff-tree)        : plumbing;;
 436                fast-import)      : import;;
 437                fast-export)      : export;;
 438                fsck-objects)     : plumbing;;
 439                fetch-pack)       : plumbing;;
 440                fmt-merge-msg)    : plumbing;;
 441                for-each-ref)     : plumbing;;
 442                hash-object)      : plumbing;;
 443                http-*)           : transport;;
 444                index-pack)       : plumbing;;
 445                init-db)          : deprecated;;
 446                local-fetch)      : plumbing;;
 447                lost-found)       : infrequent;;
 448                ls-files)         : plumbing;;
 449                ls-remote)        : plumbing;;
 450                ls-tree)          : plumbing;;
 451                mailinfo)         : plumbing;;
 452                mailsplit)        : plumbing;;
 453                merge-*)          : plumbing;;
 454                mktree)           : plumbing;;
 455                mktag)            : plumbing;;
 456                pack-objects)     : plumbing;;
 457                pack-redundant)   : plumbing;;
 458                pack-refs)        : plumbing;;
 459                parse-remote)     : plumbing;;
 460                patch-id)         : plumbing;;
 461                peek-remote)      : plumbing;;
 462                prune)            : plumbing;;
 463                prune-packed)     : plumbing;;
 464                quiltimport)      : import;;
 465                read-tree)        : plumbing;;
 466                receive-pack)     : plumbing;;
 467                reflog)           : plumbing;;
 468                repo-config)      : deprecated;;
 469                rerere)           : plumbing;;
 470                rev-list)         : plumbing;;
 471                rev-parse)        : plumbing;;
 472                runstatus)        : plumbing;;
 473                sh-setup)         : internal;;
 474                shell)            : daemon;;
 475                show-ref)         : plumbing;;
 476                send-pack)        : plumbing;;
 477                show-index)       : plumbing;;
 478                ssh-*)            : transport;;
 479                stripspace)       : plumbing;;
 480                symbolic-ref)     : plumbing;;
 481                tar-tree)         : deprecated;;
 482                unpack-file)      : plumbing;;
 483                unpack-objects)   : plumbing;;
 484                update-index)     : plumbing;;
 485                update-ref)       : plumbing;;
 486                update-server-info) : daemon;;
 487                upload-archive)   : plumbing;;
 488                upload-pack)      : plumbing;;
 489                write-tree)       : plumbing;;
 490                var)              : infrequent;;
 491                verify-pack)      : infrequent;;
 492                verify-tag)       : plumbing;;
 493                *) echo $i;;
 494                esac
 495        done
 496}
 497__git_porcelain_commandlist=
 498__git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
 499
 500__git_aliases ()
 501{
 502        local i IFS=$'\n'
 503        for i in $(git --git-dir="$(__gitdir)" config --list); do
 504                case "$i" in
 505                alias.*)
 506                        i="${i#alias.}"
 507                        echo "${i/=*/}"
 508                        ;;
 509                esac
 510        done
 511}
 512
 513# __git_aliased_command requires 1 argument
 514__git_aliased_command ()
 515{
 516        local word cmdline=$(git --git-dir="$(__gitdir)" \
 517                config --get "alias.$1")
 518        for word in $cmdline; do
 519                if [ "${word##-*}" ]; then
 520                        echo $word
 521                        return
 522                fi
 523        done
 524}
 525
 526# __git_find_subcommand requires 1 argument
 527__git_find_subcommand ()
 528{
 529        local word subcommand c=1
 530
 531        while [ $c -lt $COMP_CWORD ]; do
 532                word="${COMP_WORDS[c]}"
 533                for subcommand in $1; do
 534                        if [ "$subcommand" = "$word" ]; then
 535                                echo "$subcommand"
 536                                return
 537                        fi
 538                done
 539                c=$((++c))
 540        done
 541}
 542
 543__git_has_doubledash ()
 544{
 545        local c=1
 546        while [ $c -lt $COMP_CWORD ]; do
 547                if [ "--" = "${COMP_WORDS[c]}" ]; then
 548                        return 0
 549                fi
 550                c=$((++c))
 551        done
 552        return 1
 553}
 554
 555__git_whitespacelist="nowarn warn error error-all fix"
 556
 557_git_am ()
 558{
 559        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
 560        if [ -d "$dir"/rebase-apply ]; then
 561                __gitcomp "--skip --resolved --abort"
 562                return
 563        fi
 564        case "$cur" in
 565        --whitespace=*)
 566                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 567                return
 568                ;;
 569        --*)
 570                __gitcomp "
 571                        --signoff --utf8 --binary --3way --interactive
 572                        --whitespace=
 573                        "
 574                return
 575        esac
 576        COMPREPLY=()
 577}
 578
 579_git_apply ()
 580{
 581        local cur="${COMP_WORDS[COMP_CWORD]}"
 582        case "$cur" in
 583        --whitespace=*)
 584                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 585                return
 586                ;;
 587        --*)
 588                __gitcomp "
 589                        --stat --numstat --summary --check --index
 590                        --cached --index-info --reverse --reject --unidiff-zero
 591                        --apply --no-add --exclude=
 592                        --whitespace= --inaccurate-eof --verbose
 593                        "
 594                return
 595        esac
 596        COMPREPLY=()
 597}
 598
 599_git_add ()
 600{
 601        __git_has_doubledash && return
 602
 603        local cur="${COMP_WORDS[COMP_CWORD]}"
 604        case "$cur" in
 605        --*)
 606                __gitcomp "
 607                        --interactive --refresh --patch --update --dry-run
 608                        --ignore-errors --intent-to-add
 609                        "
 610                return
 611        esac
 612        COMPREPLY=()
 613}
 614
 615_git_archive ()
 616{
 617        local cur="${COMP_WORDS[COMP_CWORD]}"
 618        case "$cur" in
 619        --format=*)
 620                __gitcomp "$(git archive --list)" "" "${cur##--format=}"
 621                return
 622                ;;
 623        --remote=*)
 624                __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
 625                return
 626                ;;
 627        --*)
 628                __gitcomp "
 629                        --format= --list --verbose
 630                        --prefix= --remote= --exec=
 631                        "
 632                return
 633                ;;
 634        esac
 635        __git_complete_file
 636}
 637
 638_git_bisect ()
 639{
 640        __git_has_doubledash && return
 641
 642        local subcommands="start bad good skip reset visualize replay log run"
 643        local subcommand="$(__git_find_subcommand "$subcommands")"
 644        if [ -z "$subcommand" ]; then
 645                __gitcomp "$subcommands"
 646                return
 647        fi
 648
 649        case "$subcommand" in
 650        bad|good|reset|skip)
 651                __gitcomp "$(__git_refs)"
 652                ;;
 653        *)
 654                COMPREPLY=()
 655                ;;
 656        esac
 657}
 658
 659_git_branch ()
 660{
 661        local i c=1 only_local_ref="n" has_r="n"
 662
 663        while [ $c -lt $COMP_CWORD ]; do
 664                i="${COMP_WORDS[c]}"
 665                case "$i" in
 666                -d|-m)  only_local_ref="y" ;;
 667                -r)     has_r="y" ;;
 668                esac
 669                c=$((++c))
 670        done
 671
 672        case "${COMP_WORDS[COMP_CWORD]}" in
 673        --*)
 674                __gitcomp "
 675                        --color --no-color --verbose --abbrev= --no-abbrev
 676                        --track --no-track --contains --merged --no-merged
 677                        "
 678                ;;
 679        *)
 680                if [ $only_local_ref = "y" -a $has_r = "n" ]; then
 681                        __gitcomp "$(__git_heads)"
 682                else
 683                        __gitcomp "$(__git_refs)"
 684                fi
 685                ;;
 686        esac
 687}
 688
 689_git_bundle ()
 690{
 691        local cmd="${COMP_WORDS[2]}"
 692        case "$COMP_CWORD" in
 693        2)
 694                __gitcomp "create list-heads verify unbundle"
 695                ;;
 696        3)
 697                # looking for a file
 698                ;;
 699        *)
 700                case "$cmd" in
 701                        create)
 702                                __git_complete_revlist
 703                        ;;
 704                esac
 705                ;;
 706        esac
 707}
 708
 709_git_checkout ()
 710{
 711        __git_has_doubledash && return
 712
 713        __gitcomp "$(__git_refs)"
 714}
 715
 716_git_cherry ()
 717{
 718        __gitcomp "$(__git_refs)"
 719}
 720
 721_git_cherry_pick ()
 722{
 723        local cur="${COMP_WORDS[COMP_CWORD]}"
 724        case "$cur" in
 725        --*)
 726                __gitcomp "--edit --no-commit"
 727                ;;
 728        *)
 729                __gitcomp "$(__git_refs)"
 730                ;;
 731        esac
 732}
 733
 734_git_clean ()
 735{
 736        __git_has_doubledash && return
 737
 738        local cur="${COMP_WORDS[COMP_CWORD]}"
 739        case "$cur" in
 740        --*)
 741                __gitcomp "--dry-run --quiet"
 742                return
 743                ;;
 744        esac
 745        COMPREPLY=()
 746}
 747
 748_git_clone ()
 749{
 750        local cur="${COMP_WORDS[COMP_CWORD]}"
 751        case "$cur" in
 752        --*)
 753                __gitcomp "
 754                        --local
 755                        --no-hardlinks
 756                        --shared
 757                        --reference
 758                        --quiet
 759                        --no-checkout
 760                        --bare
 761                        --mirror
 762                        --origin
 763                        --upload-pack
 764                        --template=
 765                        --depth
 766                        "
 767                return
 768                ;;
 769        esac
 770        COMPREPLY=()
 771}
 772
 773_git_commit ()
 774{
 775        __git_has_doubledash && return
 776
 777        local cur="${COMP_WORDS[COMP_CWORD]}"
 778        case "$cur" in
 779        --*)
 780                __gitcomp "
 781                        --all --author= --signoff --verify --no-verify
 782                        --edit --amend --include --only --interactive
 783                        "
 784                return
 785        esac
 786        COMPREPLY=()
 787}
 788
 789_git_describe ()
 790{
 791        local cur="${COMP_WORDS[COMP_CWORD]}"
 792        case "$cur" in
 793        --*)
 794                __gitcomp "
 795                        --all --tags --contains --abbrev= --candidates=
 796                        --exact-match --debug --long --match --always
 797                        "
 798                return
 799        esac
 800        __gitcomp "$(__git_refs)"
 801}
 802
 803__git_diff_common_options="--stat --numstat --shortstat --summary
 804                        --patch-with-stat --name-only --name-status --color
 805                        --no-color --color-words --no-renames --check
 806                        --full-index --binary --abbrev --diff-filter=
 807                        --find-copies-harder
 808                        --text --ignore-space-at-eol --ignore-space-change
 809                        --ignore-all-space --exit-code --quiet --ext-diff
 810                        --no-ext-diff
 811                        --no-prefix --src-prefix= --dst-prefix=
 812                        --inter-hunk-context=
 813                        --patience
 814                        --raw
 815"
 816
 817_git_diff ()
 818{
 819        __git_has_doubledash && return
 820
 821        local cur="${COMP_WORDS[COMP_CWORD]}"
 822        case "$cur" in
 823        --*)
 824                __gitcomp "--cached --pickaxe-all --pickaxe-regex
 825                        --base --ours --theirs
 826                        $__git_diff_common_options
 827                        "
 828                return
 829                ;;
 830        esac
 831        __git_complete_file
 832}
 833
 834_git_fetch ()
 835{
 836        local cur="${COMP_WORDS[COMP_CWORD]}"
 837
 838        if [ "$COMP_CWORD" = 2 ]; then
 839                __gitcomp "$(__git_remotes)"
 840        else
 841                case "$cur" in
 842                *:*)
 843                        local pfx=""
 844                        case "$COMP_WORDBREAKS" in
 845                        *:*) : great ;;
 846                        *)   pfx="${cur%%:*}:" ;;
 847                        esac
 848                        __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
 849                        ;;
 850                *)
 851                        __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
 852                        ;;
 853                esac
 854        fi
 855}
 856
 857_git_format_patch ()
 858{
 859        local cur="${COMP_WORDS[COMP_CWORD]}"
 860        case "$cur" in
 861        --*)
 862                __gitcomp "
 863                        --stdout --attach --thread
 864                        --output-directory
 865                        --numbered --start-number
 866                        --numbered-files
 867                        --keep-subject
 868                        --signoff
 869                        --in-reply-to=
 870                        --full-index --binary
 871                        --not --all
 872                        --cover-letter
 873                        --no-prefix --src-prefix= --dst-prefix=
 874                        --inline --suffix= --ignore-if-in-upstream
 875                        --subject-prefix=
 876                        "
 877                return
 878                ;;
 879        esac
 880        __git_complete_revlist
 881}
 882
 883_git_gc ()
 884{
 885        local cur="${COMP_WORDS[COMP_CWORD]}"
 886        case "$cur" in
 887        --*)
 888                __gitcomp "--prune --aggressive"
 889                return
 890                ;;
 891        esac
 892        COMPREPLY=()
 893}
 894
 895_git_grep ()
 896{
 897        __git_has_doubledash && return
 898
 899        local cur="${COMP_WORDS[COMP_CWORD]}"
 900        case "$cur" in
 901        --*)
 902                __gitcomp "
 903                        --cached
 904                        --text --ignore-case --word-regexp --invert-match
 905                        --full-name
 906                        --extended-regexp --basic-regexp --fixed-strings
 907                        --files-with-matches --name-only
 908                        --files-without-match
 909                        --count
 910                        --and --or --not --all-match
 911                        "
 912                return
 913                ;;
 914        esac
 915        COMPREPLY=()
 916}
 917
 918_git_help ()
 919{
 920        local cur="${COMP_WORDS[COMP_CWORD]}"
 921        case "$cur" in
 922        --*)
 923                __gitcomp "--all --info --man --web"
 924                return
 925                ;;
 926        esac
 927        __gitcomp "$(__git_all_commands)
 928                attributes cli core-tutorial cvs-migration
 929                diffcore gitk glossary hooks ignore modules
 930                repository-layout tutorial tutorial-2
 931                workflows
 932                "
 933}
 934
 935_git_init ()
 936{
 937        local cur="${COMP_WORDS[COMP_CWORD]}"
 938        case "$cur" in
 939        --shared=*)
 940                __gitcomp "
 941                        false true umask group all world everybody
 942                        " "" "${cur##--shared=}"
 943                return
 944                ;;
 945        --*)
 946                __gitcomp "--quiet --bare --template= --shared --shared="
 947                return
 948                ;;
 949        esac
 950        COMPREPLY=()
 951}
 952
 953_git_ls_files ()
 954{
 955        __git_has_doubledash && return
 956
 957        local cur="${COMP_WORDS[COMP_CWORD]}"
 958        case "$cur" in
 959        --*)
 960                __gitcomp "--cached --deleted --modified --others --ignored
 961                        --stage --directory --no-empty-directory --unmerged
 962                        --killed --exclude= --exclude-from=
 963                        --exclude-per-directory= --exclude-standard
 964                        --error-unmatch --with-tree= --full-name
 965                        --abbrev --ignored --exclude-per-directory
 966                        "
 967                return
 968                ;;
 969        esac
 970        COMPREPLY=()
 971}
 972
 973_git_ls_remote ()
 974{
 975        __gitcomp "$(__git_remotes)"
 976}
 977
 978_git_ls_tree ()
 979{
 980        __git_complete_file
 981}
 982
 983__git_log_pretty_formats="oneline short medium full fuller email raw format:"
 984
 985_git_log ()
 986{
 987        __git_has_doubledash && return
 988
 989        local cur="${COMP_WORDS[COMP_CWORD]}"
 990        case "$cur" in
 991        --pretty=*)
 992                __gitcomp "$__git_log_pretty_formats
 993                        " "" "${cur##--pretty=}"
 994                return
 995                ;;
 996        --date=*)
 997                __gitcomp "
 998                        relative iso8601 rfc2822 short local default
 999                " "" "${cur##--date=}"
1000                return
1001                ;;
1002        --*)
1003                __gitcomp "
1004                        --max-count= --max-age= --since= --after=
1005                        --min-age= --before= --until=
1006                        --root --topo-order --date-order --reverse
1007                        --no-merges --follow
1008                        --abbrev-commit --abbrev=
1009                        --relative-date --date=
1010                        --author= --committer= --grep=
1011                        --all-match
1012                        --pretty=
1013                        --not --all
1014                        --left-right --cherry-pick
1015                        --graph
1016                        --decorate
1017                        --walk-reflogs
1018                        --parents --children --full-history
1019                        --merge
1020                        $__git_diff_common_options
1021                        --pickaxe-all --pickaxe-regex
1022                        "
1023                return
1024                ;;
1025        esac
1026        __git_complete_revlist
1027}
1028
1029_git_merge ()
1030{
1031        local cur="${COMP_WORDS[COMP_CWORD]}"
1032        case "${COMP_WORDS[COMP_CWORD-1]}" in
1033        -s|--strategy)
1034                __gitcomp "$(__git_merge_strategies)"
1035                return
1036        esac
1037        case "$cur" in
1038        --strategy=*)
1039                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1040                return
1041                ;;
1042        --*)
1043                __gitcomp "
1044                        --no-commit --no-stat --log --no-log --squash --strategy
1045                        "
1046                return
1047        esac
1048        __gitcomp "$(__git_refs)"
1049}
1050
1051_git_mergetool ()
1052{
1053        local cur="${COMP_WORDS[COMP_CWORD]}"
1054        case "$cur" in
1055        --tool=*)
1056                __gitcomp "
1057                        kdiff3 tkdiff meld xxdiff emerge
1058                        vimdiff gvimdiff ecmerge opendiff
1059                        " "" "${cur##--tool=}"
1060                return
1061                ;;
1062        --*)
1063                __gitcomp "--tool="
1064                return
1065                ;;
1066        esac
1067        COMPREPLY=()
1068}
1069
1070_git_merge_base ()
1071{
1072        __gitcomp "$(__git_refs)"
1073}
1074
1075_git_mv ()
1076{
1077        local cur="${COMP_WORDS[COMP_CWORD]}"
1078        case "$cur" in
1079        --*)
1080                __gitcomp "--dry-run"
1081                return
1082                ;;
1083        esac
1084        COMPREPLY=()
1085}
1086
1087_git_name_rev ()
1088{
1089        __gitcomp "--tags --all --stdin"
1090}
1091
1092_git_pull ()
1093{
1094        local cur="${COMP_WORDS[COMP_CWORD]}"
1095
1096        if [ "$COMP_CWORD" = 2 ]; then
1097                __gitcomp "$(__git_remotes)"
1098        else
1099                __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
1100        fi
1101}
1102
1103_git_push ()
1104{
1105        local cur="${COMP_WORDS[COMP_CWORD]}"
1106
1107        if [ "$COMP_CWORD" = 2 ]; then
1108                __gitcomp "$(__git_remotes)"
1109        else
1110                case "$cur" in
1111                *:*)
1112                        local pfx=""
1113                        case "$COMP_WORDBREAKS" in
1114                        *:*) : great ;;
1115                        *)   pfx="${cur%%:*}:" ;;
1116                        esac
1117
1118                        __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
1119                        ;;
1120                +*)
1121                        __gitcomp "$(__git_refs)" + "${cur#+}"
1122                        ;;
1123                *)
1124                        __gitcomp "$(__git_refs)"
1125                        ;;
1126                esac
1127        fi
1128}
1129
1130_git_rebase ()
1131{
1132        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1133        if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1134                __gitcomp "--continue --skip --abort"
1135                return
1136        fi
1137        case "${COMP_WORDS[COMP_CWORD-1]}" in
1138        -s|--strategy)
1139                __gitcomp "$(__git_merge_strategies)"
1140                return
1141        esac
1142        case "$cur" in
1143        --strategy=*)
1144                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
1145                return
1146                ;;
1147        --*)
1148                __gitcomp "--onto --merge --strategy --interactive"
1149                return
1150        esac
1151        __gitcomp "$(__git_refs)"
1152}
1153
1154_git_send_email ()
1155{
1156        local cur="${COMP_WORDS[COMP_CWORD]}"
1157        case "$cur" in
1158        --*)
1159                __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1160                        --dry-run --envelope-sender --from --identity
1161                        --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1162                        --no-suppress-from --no-thread --quiet
1163                        --signed-off-by-cc --smtp-pass --smtp-server
1164                        --smtp-server-port --smtp-ssl --smtp-user --subject
1165                        --suppress-cc --suppress-from --thread --to
1166                        --validate --no-validate"
1167                return
1168                ;;
1169        esac
1170        COMPREPLY=()
1171}
1172
1173_git_config ()
1174{
1175        local cur="${COMP_WORDS[COMP_CWORD]}"
1176        local prv="${COMP_WORDS[COMP_CWORD-1]}"
1177        case "$prv" in
1178        branch.*.remote)
1179                __gitcomp "$(__git_remotes)"
1180                return
1181                ;;
1182        branch.*.merge)
1183                __gitcomp "$(__git_refs)"
1184                return
1185                ;;
1186        remote.*.fetch)
1187                local remote="${prv#remote.}"
1188                remote="${remote%.fetch}"
1189                __gitcomp "$(__git_refs_remotes "$remote")"
1190                return
1191                ;;
1192        remote.*.push)
1193                local remote="${prv#remote.}"
1194                remote="${remote%.push}"
1195                __gitcomp "$(git --git-dir="$(__gitdir)" \
1196                        for-each-ref --format='%(refname):%(refname)' \
1197                        refs/heads)"
1198                return
1199                ;;
1200        pull.twohead|pull.octopus)
1201                __gitcomp "$(__git_merge_strategies)"
1202                return
1203                ;;
1204        color.branch|color.diff|color.status)
1205                __gitcomp "always never auto"
1206                return
1207                ;;
1208        color.*.*)
1209                __gitcomp "
1210                        normal black red green yellow blue magenta cyan white
1211                        bold dim ul blink reverse
1212                        "
1213                return
1214                ;;
1215        *.*)
1216                COMPREPLY=()
1217                return
1218                ;;
1219        esac
1220        case "$cur" in
1221        --*)
1222                __gitcomp "
1223                        --global --system --file=
1224                        --list --replace-all
1225                        --get --get-all --get-regexp
1226                        --add --unset --unset-all
1227                        --remove-section --rename-section
1228                        "
1229                return
1230                ;;
1231        branch.*.*)
1232                local pfx="${cur%.*}."
1233                cur="${cur##*.}"
1234                __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1235                return
1236                ;;
1237        branch.*)
1238                local pfx="${cur%.*}."
1239                cur="${cur#*.}"
1240                __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1241                return
1242                ;;
1243        remote.*.*)
1244                local pfx="${cur%.*}."
1245                cur="${cur##*.}"
1246                __gitcomp "
1247                        url proxy fetch push mirror skipDefaultUpdate
1248                        receivepack uploadpack tagopt
1249                        " "$pfx" "$cur"
1250                return
1251                ;;
1252        remote.*)
1253                local pfx="${cur%.*}."
1254                cur="${cur#*.}"
1255                __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1256                return
1257                ;;
1258        esac
1259        __gitcomp "
1260                apply.whitespace
1261                branch.autosetupmerge
1262                branch.autosetuprebase
1263                clean.requireForce
1264                color.branch
1265                color.branch.current
1266                color.branch.local
1267                color.branch.plain
1268                color.branch.remote
1269                color.diff
1270                color.diff.commit
1271                color.diff.frag
1272                color.diff.meta
1273                color.diff.new
1274                color.diff.old
1275                color.diff.plain
1276                color.diff.whitespace
1277                color.interactive
1278                color.interactive.header
1279                color.interactive.help
1280                color.interactive.prompt
1281                color.pager
1282                color.status
1283                color.status.added
1284                color.status.changed
1285                color.status.header
1286                color.status.nobranch
1287                color.status.untracked
1288                color.status.updated
1289                color.ui
1290                commit.template
1291                core.autocrlf
1292                core.bare
1293                core.compression
1294                core.deltaBaseCacheLimit
1295                core.editor
1296                core.excludesfile
1297                core.fileMode
1298                core.fsyncobjectfiles
1299                core.gitProxy
1300                core.ignoreCygwinFSTricks
1301                core.ignoreStat
1302                core.logAllRefUpdates
1303                core.loosecompression
1304                core.packedGitLimit
1305                core.packedGitWindowSize
1306                core.pager
1307                core.preferSymlinkRefs
1308                core.preloadindex
1309                core.quotepath
1310                core.repositoryFormatVersion
1311                core.safecrlf
1312                core.sharedRepository
1313                core.symlinks
1314                core.trustctime
1315                core.warnAmbiguousRefs
1316                core.whitespace
1317                core.worktree
1318                diff.autorefreshindex
1319                diff.external
1320                diff.mnemonicprefix
1321                diff.renameLimit
1322                diff.renameLimit.
1323                diff.renames
1324                fetch.unpackLimit
1325                format.headers
1326                format.numbered
1327                format.pretty
1328                format.suffix
1329                gc.aggressiveWindow
1330                gc.auto
1331                gc.autopacklimit
1332                gc.packrefs
1333                gc.pruneexpire
1334                gc.reflogexpire
1335                gc.reflogexpireunreachable
1336                gc.rerereresolved
1337                gc.rerereunresolved
1338                gitcvs.allbinary
1339                gitcvs.dbTableNamePrefix
1340                gitcvs.dbdriver
1341                gitcvs.dbname
1342                gitcvs.dbpass
1343                gitcvs.dbuser
1344                gitcvs.enabled
1345                gitcvs.logfile
1346                gitcvs.usecrlfattr
1347                gui.blamehistoryctx
1348                gui.commitmsgwidth
1349                gui.copyblamethreshold
1350                gui.diffcontext
1351                gui.encoding
1352                gui.fastcopyblame
1353                gui.matchtrackingbranch
1354                gui.newbranchtemplate
1355                gui.pruneduringfetch
1356                gui.spellingdictionary
1357                gui.trustmtime
1358                help.autocorrect
1359                help.browser
1360                help.format
1361                http.lowSpeedLimit
1362                http.lowSpeedTime
1363                http.maxRequests
1364                http.noEPSV
1365                http.proxy
1366                http.sslCAInfo
1367                http.sslCAPath
1368                http.sslCert
1369                http.sslKey
1370                http.sslVerify
1371                i18n.commitEncoding
1372                i18n.logOutputEncoding
1373                instaweb.browser
1374                instaweb.httpd
1375                instaweb.local
1376                instaweb.modulepath
1377                instaweb.port
1378                log.date
1379                log.showroot
1380                man.viewer
1381                merge.conflictstyle
1382                merge.log
1383                merge.renameLimit
1384                merge.stat
1385                merge.tool
1386                merge.verbosity
1387                mergetool.keepBackup
1388                pack.compression
1389                pack.deltaCacheLimit
1390                pack.deltaCacheSize
1391                pack.depth
1392                pack.indexVersion
1393                pack.packSizeLimit
1394                pack.threads
1395                pack.window
1396                pack.windowMemory
1397                pull.octopus
1398                pull.twohead
1399                receive.denyCurrentBranch
1400                receive.denyDeletes
1401                receive.denyNonFastForwards
1402                receive.fsckObjects
1403                receive.unpackLimit
1404                repack.usedeltabaseoffset
1405                rerere.autoupdate
1406                rerere.enabled
1407                showbranch.default
1408                status.relativePaths
1409                status.showUntrackedFiles
1410                tar.umask
1411                transfer.unpackLimit
1412                user.email
1413                user.name
1414                user.signingkey
1415                web.browser
1416                branch. remote.
1417        "
1418}
1419
1420_git_remote ()
1421{
1422        local subcommands="add rename rm show prune update"
1423        local subcommand="$(__git_find_subcommand "$subcommands")"
1424        if [ -z "$subcommand" ]; then
1425                __gitcomp "$subcommands"
1426                return
1427        fi
1428
1429        case "$subcommand" in
1430        rename|rm|show|prune)
1431                __gitcomp "$(__git_remotes)"
1432                ;;
1433        update)
1434                local i c='' IFS=$'\n'
1435                for i in $(git --git-dir="$(__gitdir)" config --list); do
1436                        case "$i" in
1437                        remotes.*)
1438                                i="${i#remotes.}"
1439                                c="$c ${i/=*/}"
1440                                ;;
1441                        esac
1442                done
1443                __gitcomp "$c"
1444                ;;
1445        *)
1446                COMPREPLY=()
1447                ;;
1448        esac
1449}
1450
1451_git_reset ()
1452{
1453        __git_has_doubledash && return
1454
1455        local cur="${COMP_WORDS[COMP_CWORD]}"
1456        case "$cur" in
1457        --*)
1458                __gitcomp "--merge --mixed --hard --soft"
1459                return
1460                ;;
1461        esac
1462        __gitcomp "$(__git_refs)"
1463}
1464
1465_git_revert ()
1466{
1467        local cur="${COMP_WORDS[COMP_CWORD]}"
1468        case "$cur" in
1469        --*)
1470                __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1471                return
1472                ;;
1473        esac
1474        __gitcomp "$(__git_refs)"
1475}
1476
1477_git_rm ()
1478{
1479        __git_has_doubledash && return
1480
1481        local cur="${COMP_WORDS[COMP_CWORD]}"
1482        case "$cur" in
1483        --*)
1484                __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1485                return
1486                ;;
1487        esac
1488        COMPREPLY=()
1489}
1490
1491_git_shortlog ()
1492{
1493        __git_has_doubledash && return
1494
1495        local cur="${COMP_WORDS[COMP_CWORD]}"
1496        case "$cur" in
1497        --*)
1498                __gitcomp "
1499                        --max-count= --max-age= --since= --after=
1500                        --min-age= --before= --until=
1501                        --no-merges
1502                        --author= --committer= --grep=
1503                        --all-match
1504                        --not --all
1505                        --numbered --summary
1506                        "
1507                return
1508                ;;
1509        esac
1510        __git_complete_revlist
1511}
1512
1513_git_show ()
1514{
1515        __git_has_doubledash && return
1516
1517        local cur="${COMP_WORDS[COMP_CWORD]}"
1518        case "$cur" in
1519        --pretty=*)
1520                __gitcomp "$__git_log_pretty_formats
1521                        " "" "${cur##--pretty=}"
1522                return
1523                ;;
1524        --*)
1525                __gitcomp "--pretty=
1526                        $__git_diff_common_options
1527                        "
1528                return
1529                ;;
1530        esac
1531        __git_complete_file
1532}
1533
1534_git_show_branch ()
1535{
1536        local cur="${COMP_WORDS[COMP_CWORD]}"
1537        case "$cur" in
1538        --*)
1539                __gitcomp "
1540                        --all --remotes --topo-order --current --more=
1541                        --list --independent --merge-base --no-name
1542                        --sha1-name --topics --reflog
1543                        "
1544                return
1545                ;;
1546        esac
1547        __git_complete_revlist
1548}
1549
1550_git_stash ()
1551{
1552        local subcommands='save list show apply clear drop pop create branch'
1553        local subcommand="$(__git_find_subcommand "$subcommands")"
1554        if [ -z "$subcommand" ]; then
1555                __gitcomp "$subcommands"
1556        else
1557                local cur="${COMP_WORDS[COMP_CWORD]}"
1558                case "$subcommand,$cur" in
1559                save,--*)
1560                        __gitcomp "--keep-index"
1561                        ;;
1562                apply,--*)
1563                        __gitcomp "--index"
1564                        ;;
1565                show,--*|drop,--*|pop,--*|branch,--*)
1566                        COMPREPLY=()
1567                        ;;
1568                show,*|apply,*|drop,*|pop,*|branch,*)
1569                        __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1570                                        | sed -n -e 's/:.*//p')"
1571                        ;;
1572                *)
1573                        COMPREPLY=()
1574                        ;;
1575                esac
1576        fi
1577}
1578
1579_git_submodule ()
1580{
1581        __git_has_doubledash && return
1582
1583        local subcommands="add status init update summary foreach sync"
1584        if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1585                local cur="${COMP_WORDS[COMP_CWORD]}"
1586                case "$cur" in
1587                --*)
1588                        __gitcomp "--quiet --cached"
1589                        ;;
1590                *)
1591                        __gitcomp "$subcommands"
1592                        ;;
1593                esac
1594                return
1595        fi
1596}
1597
1598_git_svn ()
1599{
1600        local subcommands="
1601                init fetch clone rebase dcommit log find-rev
1602                set-tree commit-diff info create-ignore propget
1603                proplist show-ignore show-externals
1604                "
1605        local subcommand="$(__git_find_subcommand "$subcommands")"
1606        if [ -z "$subcommand" ]; then
1607                __gitcomp "$subcommands"
1608        else
1609                local remote_opts="--username= --config-dir= --no-auth-cache"
1610                local fc_opts="
1611                        --follow-parent --authors-file= --repack=
1612                        --no-metadata --use-svm-props --use-svnsync-props
1613                        --log-window-size= --no-checkout --quiet
1614                        --repack-flags --user-log-author --localtime $remote_opts
1615                        "
1616                local init_opts="
1617                        --template= --shared= --trunk= --tags=
1618                        --branches= --stdlayout --minimize-url
1619                        --no-metadata --use-svm-props --use-svnsync-props
1620                        --rewrite-root= $remote_opts
1621                        "
1622                local cmt_opts="
1623                        --edit --rmdir --find-copies-harder --copy-similarity=
1624                        "
1625
1626                local cur="${COMP_WORDS[COMP_CWORD]}"
1627                case "$subcommand,$cur" in
1628                fetch,--*)
1629                        __gitcomp "--revision= --fetch-all $fc_opts"
1630                        ;;
1631                clone,--*)
1632                        __gitcomp "--revision= $fc_opts $init_opts"
1633                        ;;
1634                init,--*)
1635                        __gitcomp "$init_opts"
1636                        ;;
1637                dcommit,--*)
1638                        __gitcomp "
1639                                --merge --strategy= --verbose --dry-run
1640                                --fetch-all --no-rebase $cmt_opts $fc_opts
1641                                "
1642                        ;;
1643                set-tree,--*)
1644                        __gitcomp "--stdin $cmt_opts $fc_opts"
1645                        ;;
1646                create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1647                show-externals,--*)
1648                        __gitcomp "--revision="
1649                        ;;
1650                log,--*)
1651                        __gitcomp "
1652                                --limit= --revision= --verbose --incremental
1653                                --oneline --show-commit --non-recursive
1654                                --authors-file=
1655                                "
1656                        ;;
1657                rebase,--*)
1658                        __gitcomp "
1659                                --merge --verbose --strategy= --local
1660                                --fetch-all $fc_opts
1661                                "
1662                        ;;
1663                commit-diff,--*)
1664                        __gitcomp "--message= --file= --revision= $cmt_opts"
1665                        ;;
1666                info,--*)
1667                        __gitcomp "--url"
1668                        ;;
1669                *)
1670                        COMPREPLY=()
1671                        ;;
1672                esac
1673        fi
1674}
1675
1676_git_tag ()
1677{
1678        local i c=1 f=0
1679        while [ $c -lt $COMP_CWORD ]; do
1680                i="${COMP_WORDS[c]}"
1681                case "$i" in
1682                -d|-v)
1683                        __gitcomp "$(__git_tags)"
1684                        return
1685                        ;;
1686                -f)
1687                        f=1
1688                        ;;
1689                esac
1690                c=$((++c))
1691        done
1692
1693        case "${COMP_WORDS[COMP_CWORD-1]}" in
1694        -m|-F)
1695                COMPREPLY=()
1696                ;;
1697        -*|tag)
1698                if [ $f = 1 ]; then
1699                        __gitcomp "$(__git_tags)"
1700                else
1701                        COMPREPLY=()
1702                fi
1703                ;;
1704        *)
1705                __gitcomp "$(__git_refs)"
1706                ;;
1707        esac
1708}
1709
1710_git ()
1711{
1712        local i c=1 command __git_dir
1713
1714        while [ $c -lt $COMP_CWORD ]; do
1715                i="${COMP_WORDS[c]}"
1716                case "$i" in
1717                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1718                --bare)      __git_dir="." ;;
1719                --version|-p|--paginate) ;;
1720                --help) command="help"; break ;;
1721                *) command="$i"; break ;;
1722                esac
1723                c=$((++c))
1724        done
1725
1726        if [ -z "$command" ]; then
1727                case "${COMP_WORDS[COMP_CWORD]}" in
1728                --*)   __gitcomp "
1729                        --paginate
1730                        --no-pager
1731                        --git-dir=
1732                        --bare
1733                        --version
1734                        --exec-path
1735                        --work-tree=
1736                        --help
1737                        "
1738                        ;;
1739                *)     __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1740                esac
1741                return
1742        fi
1743
1744        local expansion=$(__git_aliased_command "$command")
1745        [ "$expansion" ] && command="$expansion"
1746
1747        case "$command" in
1748        am)          _git_am ;;
1749        add)         _git_add ;;
1750        apply)       _git_apply ;;
1751        archive)     _git_archive ;;
1752        bisect)      _git_bisect ;;
1753        bundle)      _git_bundle ;;
1754        branch)      _git_branch ;;
1755        checkout)    _git_checkout ;;
1756        cherry)      _git_cherry ;;
1757        cherry-pick) _git_cherry_pick ;;
1758        clean)       _git_clean ;;
1759        clone)       _git_clone ;;
1760        commit)      _git_commit ;;
1761        config)      _git_config ;;
1762        describe)    _git_describe ;;
1763        diff)        _git_diff ;;
1764        fetch)       _git_fetch ;;
1765        format-patch) _git_format_patch ;;
1766        gc)          _git_gc ;;
1767        grep)        _git_grep ;;
1768        help)        _git_help ;;
1769        init)        _git_init ;;
1770        log)         _git_log ;;
1771        ls-files)    _git_ls_files ;;
1772        ls-remote)   _git_ls_remote ;;
1773        ls-tree)     _git_ls_tree ;;
1774        merge)       _git_merge;;
1775        mergetool)   _git_mergetool;;
1776        merge-base)  _git_merge_base ;;
1777        mv)          _git_mv ;;
1778        name-rev)    _git_name_rev ;;
1779        pull)        _git_pull ;;
1780        push)        _git_push ;;
1781        rebase)      _git_rebase ;;
1782        remote)      _git_remote ;;
1783        reset)       _git_reset ;;
1784        revert)      _git_revert ;;
1785        rm)          _git_rm ;;
1786        send-email)  _git_send_email ;;
1787        shortlog)    _git_shortlog ;;
1788        show)        _git_show ;;
1789        show-branch) _git_show_branch ;;
1790        stash)       _git_stash ;;
1791        stage)       _git_add ;;
1792        submodule)   _git_submodule ;;
1793        svn)         _git_svn ;;
1794        tag)         _git_tag ;;
1795        whatchanged) _git_log ;;
1796        *)           COMPREPLY=() ;;
1797        esac
1798}
1799
1800_gitk ()
1801{
1802        __git_has_doubledash && return
1803
1804        local cur="${COMP_WORDS[COMP_CWORD]}"
1805        local g="$(__gitdir)"
1806        local merge=""
1807        if [ -f $g/MERGE_HEAD ]; then
1808                merge="--merge"
1809        fi
1810        case "$cur" in
1811        --*)
1812                __gitcomp "--not --all $merge"
1813                return
1814                ;;
1815        esac
1816        __git_complete_revlist
1817}
1818
1819complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1820        || complete -o default -o nospace -F _git git
1821complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1822        || complete -o default -o nospace -F _gitk gitk
1823
1824# The following are necessary only for Cygwin, and only are needed
1825# when the user has tab-completed the executable name and consequently
1826# included the '.exe' suffix.
1827#
1828if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1829complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1830        || complete -o default -o nospace -F _git git.exe
1831fi