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