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