contrib / completion / git-completion.bashon commit git-request-pull: replace call to deprecated peek-remote (7498205)
   1#
   2# bash completion support for core Git.
   3#
   4# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
   5# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
   6# Distributed under the GNU General Public License, version 2.0.
   7#
   8# The contained completion routines provide support for completing:
   9#
  10#    *) local and remote branch names
  11#    *) local and remote tag names
  12#    *) .git/remotes file names
  13#    *) git 'subcommands'
  14#    *) tree paths within 'ref:path/to/file' expressions
  15#    *) common --long-options
  16#
  17# To use these routines:
  18#
  19#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  20#    2) Added the following line to your .bashrc:
  21#        source ~/.git-completion.sh
  22#
  23#    3) You may want to make sure the git executable is available
  24#       in your PATH before this script is sourced, as some caching
  25#       is performed while the script loads.  If git isn't found
  26#       at source time then all lookups will be done on demand,
  27#       which may be slightly slower.
  28#
  29#    4) Consider changing your PS1 to also show the current branch:
  30#        PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
  31#
  32#       The argument to __git_ps1 will be displayed only if you
  33#       are currently in a git repository.  The %s token will be
  34#       the name of the current branch.
  35#
  36# To submit patches:
  37#
  38#    *) Read Documentation/SubmittingPatches
  39#    *) Send all patches to the current maintainer:
  40#
  41#       "Shawn O. Pearce" <spearce@spearce.org>
  42#
  43#    *) Always CC the Git mailing list:
  44#
  45#       git@vger.kernel.org
  46#
  47
  48__gitdir ()
  49{
  50        if [ -z "$1" ]; then
  51                if [ -n "$__git_dir" ]; then
  52                        echo "$__git_dir"
  53                elif [ -d .git ]; then
  54                        echo .git
  55                else
  56                        git rev-parse --git-dir 2>/dev/null
  57                fi
  58        elif [ -d "$1/.git" ]; then
  59                echo "$1/.git"
  60        else
  61                echo "$1"
  62        fi
  63}
  64
  65__git_ps1 ()
  66{
  67        local g="$(git rev-parse --git-dir 2>/dev/null)"
  68        if [ -n "$g" ]; then
  69                local r
  70                local b
  71                if [ -d "$g/../.dotest" ]
  72                then
  73                        if test -f "$g/../.dotest/rebasing"
  74                        then
  75                                r="|REBASE"
  76                        elif test -f "$g/../.dotest/applying"
  77                        then
  78                                r="|AM"
  79                        else
  80                                r="|AM/REBASE"
  81                        fi
  82                        b="$(git symbolic-ref HEAD 2>/dev/null)"
  83                elif [ -f "$g/.dotest-merge/interactive" ]
  84                then
  85                        r="|REBASE-i"
  86                        b="$(cat "$g/.dotest-merge/head-name")"
  87                elif [ -d "$g/.dotest-merge" ]
  88                then
  89                        r="|REBASE-m"
  90                        b="$(cat "$g/.dotest-merge/head-name")"
  91                elif [ -f "$g/MERGE_HEAD" ]
  92                then
  93                        r="|MERGING"
  94                        b="$(git symbolic-ref HEAD 2>/dev/null)"
  95                else
  96                        if [ -f "$g/BISECT_LOG" ]
  97                        then
  98                                r="|BISECTING"
  99                        fi
 100                        if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
 101                        then
 102                                if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
 103                                then
 104                                        b="$(cut -c1-7 "$g/HEAD")..."
 105                                fi
 106                        fi
 107                fi
 108
 109                if [ -n "$1" ]; then
 110                        printf "$1" "${b##refs/heads/}$r"
 111                else
 112                        printf " (%s)" "${b##refs/heads/}$r"
 113                fi
 114        fi
 115}
 116
 117__gitcomp ()
 118{
 119        local all c s=$'\n' IFS=' '$'\t'$'\n'
 120        local cur="${COMP_WORDS[COMP_CWORD]}"
 121        if [ $# -gt 2 ]; then
 122                cur="$3"
 123        fi
 124        case "$cur" in
 125        --*=)
 126                COMPREPLY=()
 127                return
 128                ;;
 129        *)
 130                for c in $1; do
 131                        case "$c$4" in
 132                        --*=*) all="$all$c$4$s" ;;
 133                        *.)    all="$all$c$4$s" ;;
 134                        *)     all="$all$c$4 $s" ;;
 135                        esac
 136                done
 137                ;;
 138        esac
 139        IFS=$s
 140        COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
 141        return
 142}
 143
 144__git_heads ()
 145{
 146        local cmd i is_hash=y dir="$(__gitdir "$1")"
 147        if [ -d "$dir" ]; then
 148                for i in $(git --git-dir="$dir" \
 149                        for-each-ref --format='%(refname)' \
 150                        refs/heads ); do
 151                        echo "${i#refs/heads/}"
 152                done
 153                return
 154        fi
 155        for i in $(git ls-remote "$1" 2>/dev/null); do
 156                case "$is_hash,$i" in
 157                y,*) is_hash=n ;;
 158                n,*^{}) is_hash=y ;;
 159                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
 160                n,*) is_hash=y; echo "$i" ;;
 161                esac
 162        done
 163}
 164
 165__git_tags ()
 166{
 167        local cmd i is_hash=y dir="$(__gitdir "$1")"
 168        if [ -d "$dir" ]; then
 169                for i in $(git --git-dir="$dir" \
 170                        for-each-ref --format='%(refname)' \
 171                        refs/tags ); do
 172                        echo "${i#refs/tags/}"
 173                done
 174                return
 175        fi
 176        for i in $(git ls-remote "$1" 2>/dev/null); do
 177                case "$is_hash,$i" in
 178                y,*) is_hash=n ;;
 179                n,*^{}) is_hash=y ;;
 180                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 181                n,*) is_hash=y; echo "$i" ;;
 182                esac
 183        done
 184}
 185
 186__git_refs ()
 187{
 188        local cmd i is_hash=y dir="$(__gitdir "$1")"
 189        if [ -d "$dir" ]; then
 190                if [ -e "$dir/HEAD" ]; then echo HEAD; fi
 191                for i in $(git --git-dir="$dir" \
 192                        for-each-ref --format='%(refname)' \
 193                        refs/tags refs/heads refs/remotes); do
 194                        case "$i" in
 195                                refs/tags/*)    echo "${i#refs/tags/}" ;;
 196                                refs/heads/*)   echo "${i#refs/heads/}" ;;
 197                                refs/remotes/*) echo "${i#refs/remotes/}" ;;
 198                                *)              echo "$i" ;;
 199                        esac
 200                done
 201                return
 202        fi
 203        for i in $(git ls-remote "$dir" 2>/dev/null); do
 204                case "$is_hash,$i" in
 205                y,*) is_hash=n ;;
 206                n,*^{}) is_hash=y ;;
 207                n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
 208                n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
 209                n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
 210                n,*) is_hash=y; echo "$i" ;;
 211                esac
 212        done
 213}
 214
 215__git_refs2 ()
 216{
 217        local i
 218        for i in $(__git_refs "$1"); do
 219                echo "$i:$i"
 220        done
 221}
 222
 223__git_refs_remotes ()
 224{
 225        local cmd i is_hash=y
 226        for i in $(git ls-remote "$1" 2>/dev/null); do
 227                case "$is_hash,$i" in
 228                n,refs/heads/*)
 229                        is_hash=y
 230                        echo "$i:refs/remotes/$1/${i#refs/heads/}"
 231                        ;;
 232                y,*) is_hash=n ;;
 233                n,*^{}) is_hash=y ;;
 234                n,refs/tags/*) is_hash=y;;
 235                n,*) is_hash=y; ;;
 236                esac
 237        done
 238}
 239
 240__git_remotes ()
 241{
 242        local i ngoff IFS=$'\n' d="$(__gitdir)"
 243        shopt -q nullglob || ngoff=1
 244        shopt -s nullglob
 245        for i in "$d/remotes"/*; do
 246                echo ${i#$d/remotes/}
 247        done
 248        [ "$ngoff" ] && shopt -u nullglob
 249        for i in $(git --git-dir="$d" config --list); do
 250                case "$i" in
 251                remote.*.url=*)
 252                        i="${i#remote.}"
 253                        echo "${i/.url=*/}"
 254                        ;;
 255                esac
 256        done
 257}
 258
 259__git_merge_strategies ()
 260{
 261        if [ -n "$__git_merge_strategylist" ]; then
 262                echo "$__git_merge_strategylist"
 263                return
 264        fi
 265        sed -n "/^all_strategies='/{
 266                s/^all_strategies='//
 267                s/'//
 268                p
 269                q
 270                }" "$(git --exec-path)/git-merge"
 271}
 272__git_merge_strategylist=
 273__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
 274
 275__git_complete_file ()
 276{
 277        local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
 278        case "$cur" in
 279        ?*:*)
 280                ref="${cur%%:*}"
 281                cur="${cur#*:}"
 282                case "$cur" in
 283                ?*/*)
 284                        pfx="${cur%/*}"
 285                        cur="${cur##*/}"
 286                        ls="$ref:$pfx"
 287                        pfx="$pfx/"
 288                        ;;
 289                *)
 290                        ls="$ref"
 291                        ;;
 292            esac
 293                COMPREPLY=($(compgen -P "$pfx" \
 294                        -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
 295                                | sed '/^100... blob /s,^.*     ,,
 296                                       /^040000 tree /{
 297                                           s,^.*        ,,
 298                                           s,$,/,
 299                                       }
 300                                       s/^.*    //')" \
 301                        -- "$cur"))
 302                ;;
 303        *)
 304                __gitcomp "$(__git_refs)"
 305                ;;
 306        esac
 307}
 308
 309__git_complete_revlist ()
 310{
 311        local pfx cur="${COMP_WORDS[COMP_CWORD]}"
 312        case "$cur" in
 313        *...*)
 314                pfx="${cur%...*}..."
 315                cur="${cur#*...}"
 316                __gitcomp "$(__git_refs)" "$pfx" "$cur"
 317                ;;
 318        *..*)
 319                pfx="${cur%..*}.."
 320                cur="${cur#*..}"
 321                __gitcomp "$(__git_refs)" "$pfx" "$cur"
 322                ;;
 323        *.)
 324                __gitcomp "$cur."
 325                ;;
 326        *)
 327                __gitcomp "$(__git_refs)"
 328                ;;
 329        esac
 330}
 331
 332__git_commands ()
 333{
 334        if [ -n "$__git_commandlist" ]; then
 335                echo "$__git_commandlist"
 336                return
 337        fi
 338        local i IFS=" "$'\n'
 339        for i in $(git help -a|egrep '^ ')
 340        do
 341                case $i in
 342                *--*)             : helper pattern;;
 343                applymbox)        : ask gittus;;
 344                applypatch)       : ask gittus;;
 345                archimport)       : import;;
 346                cat-file)         : plumbing;;
 347                check-attr)       : plumbing;;
 348                check-ref-format) : plumbing;;
 349                commit-tree)      : plumbing;;
 350                cvsexportcommit)  : export;;
 351                cvsimport)        : import;;
 352                cvsserver)        : daemon;;
 353                daemon)           : daemon;;
 354                diff-files)       : plumbing;;
 355                diff-index)       : plumbing;;
 356                diff-tree)        : plumbing;;
 357                fast-import)      : import;;
 358                fsck-objects)     : plumbing;;
 359                fetch-pack)       : plumbing;;
 360                fmt-merge-msg)    : plumbing;;
 361                for-each-ref)     : plumbing;;
 362                hash-object)      : plumbing;;
 363                http-*)           : transport;;
 364                index-pack)       : plumbing;;
 365                init-db)          : deprecated;;
 366                local-fetch)      : plumbing;;
 367                mailinfo)         : plumbing;;
 368                mailsplit)        : plumbing;;
 369                merge-*)          : plumbing;;
 370                mktree)           : plumbing;;
 371                mktag)            : plumbing;;
 372                pack-objects)     : plumbing;;
 373                pack-redundant)   : plumbing;;
 374                pack-refs)        : plumbing;;
 375                parse-remote)     : plumbing;;
 376                patch-id)         : plumbing;;
 377                peek-remote)      : plumbing;;
 378                prune)            : plumbing;;
 379                prune-packed)     : plumbing;;
 380                quiltimport)      : import;;
 381                read-tree)        : plumbing;;
 382                receive-pack)     : plumbing;;
 383                reflog)           : plumbing;;
 384                repo-config)      : deprecated;;
 385                rerere)           : plumbing;;
 386                rev-list)         : plumbing;;
 387                rev-parse)        : plumbing;;
 388                runstatus)        : plumbing;;
 389                sh-setup)         : internal;;
 390                shell)            : daemon;;
 391                send-pack)        : plumbing;;
 392                show-index)       : plumbing;;
 393                ssh-*)            : transport;;
 394                stripspace)       : plumbing;;
 395                symbolic-ref)     : plumbing;;
 396                tar-tree)         : deprecated;;
 397                unpack-file)      : plumbing;;
 398                unpack-objects)   : plumbing;;
 399                update-index)     : plumbing;;
 400                update-ref)       : plumbing;;
 401                update-server-info) : daemon;;
 402                upload-archive)   : plumbing;;
 403                upload-pack)      : plumbing;;
 404                write-tree)       : plumbing;;
 405                verify-tag)       : plumbing;;
 406                *) echo $i;;
 407                esac
 408        done
 409}
 410__git_commandlist=
 411__git_commandlist="$(__git_commands 2>/dev/null)"
 412
 413__git_aliases ()
 414{
 415        local i IFS=$'\n'
 416        for i in $(git --git-dir="$(__gitdir)" config --list); do
 417                case "$i" in
 418                alias.*)
 419                        i="${i#alias.}"
 420                        echo "${i/=*/}"
 421                        ;;
 422                esac
 423        done
 424}
 425
 426__git_aliased_command ()
 427{
 428        local word cmdline=$(git --git-dir="$(__gitdir)" \
 429                config --get "alias.$1")
 430        for word in $cmdline; do
 431                if [ "${word##-*}" ]; then
 432                        echo $word
 433                        return
 434                fi
 435        done
 436}
 437
 438__git_find_subcommand ()
 439{
 440        local word subcommand c=1
 441
 442        while [ $c -lt $COMP_CWORD ]; do
 443                word="${COMP_WORDS[c]}"
 444                for subcommand in $1; do
 445                        if [ "$subcommand" = "$word" ]; then
 446                                echo "$subcommand"
 447                                return
 448                        fi
 449                done
 450                c=$((++c))
 451        done
 452}
 453
 454__git_has_doubledash ()
 455{
 456        local c=1
 457        while [ $c -lt $COMP_CWORD ]; do
 458                if [ "--" = "${COMP_WORDS[c]}" ]; then
 459                        return 0
 460                fi
 461                c=$((++c))
 462        done
 463        return 1
 464}
 465
 466__git_whitespacelist="nowarn warn error error-all strip"
 467
 468_git_am ()
 469{
 470        local cur="${COMP_WORDS[COMP_CWORD]}"
 471        if [ -d .dotest ]; then
 472                __gitcomp "--skip --resolved"
 473                return
 474        fi
 475        case "$cur" in
 476        --whitespace=*)
 477                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 478                return
 479                ;;
 480        --*)
 481                __gitcomp "
 482                        --signoff --utf8 --binary --3way --interactive
 483                        --whitespace=
 484                        "
 485                return
 486        esac
 487        COMPREPLY=()
 488}
 489
 490_git_apply ()
 491{
 492        local cur="${COMP_WORDS[COMP_CWORD]}"
 493        case "$cur" in
 494        --whitespace=*)
 495                __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
 496                return
 497                ;;
 498        --*)
 499                __gitcomp "
 500                        --stat --numstat --summary --check --index
 501                        --cached --index-info --reverse --reject --unidiff-zero
 502                        --apply --no-add --exclude=
 503                        --whitespace= --inaccurate-eof --verbose
 504                        "
 505                return
 506        esac
 507        COMPREPLY=()
 508}
 509
 510_git_add ()
 511{
 512        __git_has_doubledash && return
 513
 514        local cur="${COMP_WORDS[COMP_CWORD]}"
 515        case "$cur" in
 516        --*)
 517                __gitcomp "
 518                        --interactive --refresh --patch --update --dry-run
 519                        --ignore-errors
 520                        "
 521                return
 522        esac
 523        COMPREPLY=()
 524}
 525
 526_git_bisect ()
 527{
 528        __git_has_doubledash && return
 529
 530        local subcommands="start bad good skip reset visualize replay log run"
 531        local subcommand="$(__git_find_subcommand "$subcommands")"
 532        if [ -z "$subcommand" ]; then
 533                __gitcomp "$subcommands"
 534                return
 535        fi
 536
 537        case "$subcommand" in
 538        bad|good|reset|skip)
 539                __gitcomp "$(__git_refs)"
 540                ;;
 541        *)
 542                COMPREPLY=()
 543                ;;
 544        esac
 545}
 546
 547_git_branch ()
 548{
 549        local i c=1 only_local_ref="n" has_r="n"
 550
 551        while [ $c -lt $COMP_CWORD ]; do
 552                i="${COMP_WORDS[c]}"
 553                case "$i" in
 554                -d|-m)  only_local_ref="y" ;;
 555                -r)     has_r="y" ;;
 556                esac
 557                c=$((++c))
 558        done
 559
 560        case "${COMP_WORDS[COMP_CWORD]}" in
 561        --*=*)  COMPREPLY=() ;;
 562        --*)
 563                __gitcomp "
 564                        --color --no-color --verbose --abbrev= --no-abbrev
 565                        --track --no-track --contains --merged --no-merged
 566                        "
 567                ;;
 568        *)
 569                if [ $only_local_ref = "y" -a $has_r = "n" ]; then
 570                        __gitcomp "$(__git_heads)"
 571                else
 572                        __gitcomp "$(__git_refs)"
 573                fi
 574                ;;
 575        esac
 576}
 577
 578_git_bundle ()
 579{
 580        local mycword="$COMP_CWORD"
 581        case "${COMP_WORDS[0]}" in
 582        git)
 583                local cmd="${COMP_WORDS[2]}"
 584                mycword="$((mycword-1))"
 585                ;;
 586        git-bundle*)
 587                local cmd="${COMP_WORDS[1]}"
 588                ;;
 589        esac
 590        case "$mycword" in
 591        1)
 592                __gitcomp "create list-heads verify unbundle"
 593                ;;
 594        2)
 595                # looking for a file
 596                ;;
 597        *)
 598                case "$cmd" in
 599                        create)
 600                                __git_complete_revlist
 601                        ;;
 602                esac
 603                ;;
 604        esac
 605}
 606
 607_git_checkout ()
 608{
 609        __gitcomp "$(__git_refs)"
 610}
 611
 612_git_cherry ()
 613{
 614        __gitcomp "$(__git_refs)"
 615}
 616
 617_git_cherry_pick ()
 618{
 619        local cur="${COMP_WORDS[COMP_CWORD]}"
 620        case "$cur" in
 621        --*)
 622                __gitcomp "--edit --no-commit"
 623                ;;
 624        *)
 625                __gitcomp "$(__git_refs)"
 626                ;;
 627        esac
 628}
 629
 630_git_commit ()
 631{
 632        __git_has_doubledash && return
 633
 634        local cur="${COMP_WORDS[COMP_CWORD]}"
 635        case "$cur" in
 636        --*)
 637                __gitcomp "
 638                        --all --author= --signoff --verify --no-verify
 639                        --edit --amend --include --only
 640                        "
 641                return
 642        esac
 643        COMPREPLY=()
 644}
 645
 646_git_describe ()
 647{
 648        __gitcomp "$(__git_refs)"
 649}
 650
 651_git_diff ()
 652{
 653        __git_has_doubledash && return
 654
 655        local cur="${COMP_WORDS[COMP_CWORD]}"
 656        case "$cur" in
 657        --*)
 658                __gitcomp "--cached --stat --numstat --shortstat --summary
 659                        --patch-with-stat --name-only --name-status --color
 660                        --no-color --color-words --no-renames --check
 661                        --full-index --binary --abbrev --diff-filter
 662                        --find-copies-harder --pickaxe-all --pickaxe-regex
 663                        --text --ignore-space-at-eol --ignore-space-change
 664                        --ignore-all-space --exit-code --quiet --ext-diff
 665                        --no-ext-diff
 666                        --no-prefix --src-prefix= --dst-prefix=
 667                        --base --ours --theirs
 668                        "
 669                return
 670                ;;
 671        esac
 672        __git_complete_file
 673}
 674
 675_git_diff_tree ()
 676{
 677        __gitcomp "$(__git_refs)"
 678}
 679
 680_git_fetch ()
 681{
 682        local cur="${COMP_WORDS[COMP_CWORD]}"
 683
 684        case "${COMP_WORDS[0]},$COMP_CWORD" in
 685        git-fetch*,1)
 686                __gitcomp "$(__git_remotes)"
 687                ;;
 688        git,2)
 689                __gitcomp "$(__git_remotes)"
 690                ;;
 691        *)
 692                case "$cur" in
 693                *:*)
 694                        __gitcomp "$(__git_refs)" "" "${cur#*:}"
 695                        ;;
 696                *)
 697                        local remote
 698                        case "${COMP_WORDS[0]}" in
 699                        git-fetch) remote="${COMP_WORDS[1]}" ;;
 700                        git)       remote="${COMP_WORDS[2]}" ;;
 701                        esac
 702                        __gitcomp "$(__git_refs2 "$remote")"
 703                        ;;
 704                esac
 705                ;;
 706        esac
 707}
 708
 709_git_format_patch ()
 710{
 711        local cur="${COMP_WORDS[COMP_CWORD]}"
 712        case "$cur" in
 713        --*)
 714                __gitcomp "
 715                        --stdout --attach --thread
 716                        --output-directory
 717                        --numbered --start-number
 718                        --numbered-files
 719                        --keep-subject
 720                        --signoff
 721                        --in-reply-to=
 722                        --full-index --binary
 723                        --not --all
 724                        --cover-letter
 725                        --no-prefix --src-prefix= --dst-prefix=
 726                        "
 727                return
 728                ;;
 729        esac
 730        __git_complete_revlist
 731}
 732
 733_git_gc ()
 734{
 735        local cur="${COMP_WORDS[COMP_CWORD]}"
 736        case "$cur" in
 737        --*)
 738                __gitcomp "--prune --aggressive"
 739                return
 740                ;;
 741        esac
 742        COMPREPLY=()
 743}
 744
 745_git_ls_remote ()
 746{
 747        __gitcomp "$(__git_remotes)"
 748}
 749
 750_git_ls_tree ()
 751{
 752        __git_complete_file
 753}
 754
 755_git_log ()
 756{
 757        __git_has_doubledash && return
 758
 759        local cur="${COMP_WORDS[COMP_CWORD]}"
 760        case "$cur" in
 761        --pretty=*)
 762                __gitcomp "
 763                        oneline short medium full fuller email raw
 764                        " "" "${cur##--pretty=}"
 765                return
 766                ;;
 767        --date=*)
 768                __gitcomp "
 769                        relative iso8601 rfc2822 short local default
 770                " "" "${cur##--date=}"
 771                return
 772                ;;
 773        --*)
 774                __gitcomp "
 775                        --max-count= --max-age= --since= --after=
 776                        --min-age= --before= --until=
 777                        --root --topo-order --date-order --reverse
 778                        --no-merges --follow
 779                        --abbrev-commit --abbrev=
 780                        --relative-date --date=
 781                        --author= --committer= --grep=
 782                        --all-match
 783                        --pretty= --name-status --name-only --raw
 784                        --not --all
 785                        --left-right --cherry-pick
 786                        --graph
 787                        --stat --numstat --shortstat
 788                        --decorate --diff-filter=
 789                        --color-words --walk-reflogs
 790                        "
 791                return
 792                ;;
 793        esac
 794        __git_complete_revlist
 795}
 796
 797_git_merge ()
 798{
 799        local cur="${COMP_WORDS[COMP_CWORD]}"
 800        case "${COMP_WORDS[COMP_CWORD-1]}" in
 801        -s|--strategy)
 802                __gitcomp "$(__git_merge_strategies)"
 803                return
 804        esac
 805        case "$cur" in
 806        --strategy=*)
 807                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
 808                return
 809                ;;
 810        --*)
 811                __gitcomp "
 812                        --no-commit --no-stat --log --no-log --squash --strategy
 813                        "
 814                return
 815        esac
 816        __gitcomp "$(__git_refs)"
 817}
 818
 819_git_merge_base ()
 820{
 821        __gitcomp "$(__git_refs)"
 822}
 823
 824_git_name_rev ()
 825{
 826        __gitcomp "--tags --all --stdin"
 827}
 828
 829_git_pull ()
 830{
 831        local cur="${COMP_WORDS[COMP_CWORD]}"
 832
 833        case "${COMP_WORDS[0]},$COMP_CWORD" in
 834        git-pull*,1)
 835                __gitcomp "$(__git_remotes)"
 836                ;;
 837        git,2)
 838                __gitcomp "$(__git_remotes)"
 839                ;;
 840        *)
 841                local remote
 842                case "${COMP_WORDS[0]}" in
 843                git-pull)  remote="${COMP_WORDS[1]}" ;;
 844                git)       remote="${COMP_WORDS[2]}" ;;
 845                esac
 846                __gitcomp "$(__git_refs "$remote")"
 847                ;;
 848        esac
 849}
 850
 851_git_push ()
 852{
 853        local cur="${COMP_WORDS[COMP_CWORD]}"
 854
 855        case "${COMP_WORDS[0]},$COMP_CWORD" in
 856        git-push*,1)
 857                __gitcomp "$(__git_remotes)"
 858                ;;
 859        git,2)
 860                __gitcomp "$(__git_remotes)"
 861                ;;
 862        *)
 863                case "$cur" in
 864                *:*)
 865                        local remote
 866                        case "${COMP_WORDS[0]}" in
 867                        git-push)  remote="${COMP_WORDS[1]}" ;;
 868                        git)       remote="${COMP_WORDS[2]}" ;;
 869                        esac
 870                        __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}"
 871                        ;;
 872                +*)
 873                        __gitcomp "$(__git_refs)" + "${cur#+}"
 874                        ;;
 875                *)
 876                        __gitcomp "$(__git_refs)"
 877                        ;;
 878                esac
 879                ;;
 880        esac
 881}
 882
 883_git_rebase ()
 884{
 885        local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
 886        if [ -d .dotest ] || [ -d "$dir"/.dotest-merge ]; then
 887                __gitcomp "--continue --skip --abort"
 888                return
 889        fi
 890        case "${COMP_WORDS[COMP_CWORD-1]}" in
 891        -s|--strategy)
 892                __gitcomp "$(__git_merge_strategies)"
 893                return
 894        esac
 895        case "$cur" in
 896        --strategy=*)
 897                __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
 898                return
 899                ;;
 900        --*)
 901                __gitcomp "--onto --merge --strategy --interactive"
 902                return
 903        esac
 904        __gitcomp "$(__git_refs)"
 905}
 906
 907_git_config ()
 908{
 909        local cur="${COMP_WORDS[COMP_CWORD]}"
 910        local prv="${COMP_WORDS[COMP_CWORD-1]}"
 911        case "$prv" in
 912        branch.*.remote)
 913                __gitcomp "$(__git_remotes)"
 914                return
 915                ;;
 916        branch.*.merge)
 917                __gitcomp "$(__git_refs)"
 918                return
 919                ;;
 920        remote.*.fetch)
 921                local remote="${prv#remote.}"
 922                remote="${remote%.fetch}"
 923                __gitcomp "$(__git_refs_remotes "$remote")"
 924                return
 925                ;;
 926        remote.*.push)
 927                local remote="${prv#remote.}"
 928                remote="${remote%.push}"
 929                __gitcomp "$(git --git-dir="$(__gitdir)" \
 930                        for-each-ref --format='%(refname):%(refname)' \
 931                        refs/heads)"
 932                return
 933                ;;
 934        pull.twohead|pull.octopus)
 935                __gitcomp "$(__git_merge_strategies)"
 936                return
 937                ;;
 938        color.branch|color.diff|color.status)
 939                __gitcomp "always never auto"
 940                return
 941                ;;
 942        color.*.*)
 943                __gitcomp "
 944                        black red green yellow blue magenta cyan white
 945                        bold dim ul blink reverse
 946                        "
 947                return
 948                ;;
 949        *.*)
 950                COMPREPLY=()
 951                return
 952                ;;
 953        esac
 954        case "$cur" in
 955        --*)
 956                __gitcomp "
 957                        --global --system --file=
 958                        --list --replace-all
 959                        --get --get-all --get-regexp
 960                        --add --unset --unset-all
 961                        --remove-section --rename-section
 962                        "
 963                return
 964                ;;
 965        branch.*.*)
 966                local pfx="${cur%.*}."
 967                cur="${cur##*.}"
 968                __gitcomp "remote merge" "$pfx" "$cur"
 969                return
 970                ;;
 971        branch.*)
 972                local pfx="${cur%.*}."
 973                cur="${cur#*.}"
 974                __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
 975                return
 976                ;;
 977        remote.*.*)
 978                local pfx="${cur%.*}."
 979                cur="${cur##*.}"
 980                __gitcomp "
 981                        url fetch push skipDefaultUpdate
 982                        receivepack uploadpack tagopt
 983                        " "$pfx" "$cur"
 984                return
 985                ;;
 986        remote.*)
 987                local pfx="${cur%.*}."
 988                cur="${cur#*.}"
 989                __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
 990                return
 991                ;;
 992        esac
 993        __gitcomp "
 994                apply.whitespace
 995                core.fileMode
 996                core.gitProxy
 997                core.ignoreStat
 998                core.preferSymlinkRefs
 999                core.logAllRefUpdates
1000                core.loosecompression
1001                core.repositoryFormatVersion
1002                core.sharedRepository
1003                core.warnAmbiguousRefs
1004                core.compression
1005                core.packedGitWindowSize
1006                core.packedGitLimit
1007                clean.requireForce
1008                color.branch
1009                color.branch.current
1010                color.branch.local
1011                color.branch.remote
1012                color.branch.plain
1013                color.diff
1014                color.diff.plain
1015                color.diff.meta
1016                color.diff.frag
1017                color.diff.old
1018                color.diff.new
1019                color.diff.commit
1020                color.diff.whitespace
1021                color.pager
1022                color.status
1023                color.status.header
1024                color.status.added
1025                color.status.changed
1026                color.status.untracked
1027                diff.renameLimit
1028                diff.renames
1029                fetch.unpackLimit
1030                format.headers
1031                format.subjectprefix
1032                gitcvs.enabled
1033                gitcvs.logfile
1034                gitcvs.allbinary
1035                gitcvs.dbname gitcvs.dbdriver gitcvs.dbuser gitcvs.dbpass
1036                gitcvs.dbtablenameprefix
1037                gc.packrefs
1038                gc.reflogexpire
1039                gc.reflogexpireunreachable
1040                gc.rerereresolved
1041                gc.rerereunresolved
1042                http.sslVerify
1043                http.sslCert
1044                http.sslKey
1045                http.sslCAInfo
1046                http.sslCAPath
1047                http.maxRequests
1048                http.lowSpeedLimit
1049                http.lowSpeedTime
1050                http.noEPSV
1051                i18n.commitEncoding
1052                i18n.logOutputEncoding
1053                log.showroot
1054                merge.tool
1055                merge.summary
1056                merge.verbosity
1057                pack.window
1058                pack.depth
1059                pack.windowMemory
1060                pack.compression
1061                pack.deltaCacheSize
1062                pack.deltaCacheLimit
1063                pull.octopus
1064                pull.twohead
1065                repack.useDeltaBaseOffset
1066                showbranch.default
1067                tar.umask
1068                transfer.unpackLimit
1069                receive.unpackLimit
1070                receive.denyNonFastForwards
1071                user.name
1072                user.email
1073                user.signingkey
1074                branch. remote.
1075        "
1076}
1077
1078_git_remote ()
1079{
1080        local subcommands="add rm show prune update"
1081        local subcommand="$(__git_find_subcommand "$subcommands")"
1082        if [ -z "$subcommand" ]; then
1083                __gitcomp "$subcommands"
1084                return
1085        fi
1086
1087        case "$subcommand" in
1088        rm|show|prune)
1089                __gitcomp "$(__git_remotes)"
1090                ;;
1091        update)
1092                local i c='' IFS=$'\n'
1093                for i in $(git --git-dir="$(__gitdir)" config --list); do
1094                        case "$i" in
1095                        remotes.*)
1096                                i="${i#remotes.}"
1097                                c="$c ${i/=*/}"
1098                                ;;
1099                        esac
1100                done
1101                __gitcomp "$c"
1102                ;;
1103        *)
1104                COMPREPLY=()
1105                ;;
1106        esac
1107}
1108
1109_git_reset ()
1110{
1111        __git_has_doubledash && return
1112
1113        local cur="${COMP_WORDS[COMP_CWORD]}"
1114        case "$cur" in
1115        --*)
1116                __gitcomp "--mixed --hard --soft"
1117                return
1118                ;;
1119        esac
1120        __gitcomp "$(__git_refs)"
1121}
1122
1123_git_shortlog ()
1124{
1125        __git_has_doubledash && return
1126
1127        local cur="${COMP_WORDS[COMP_CWORD]}"
1128        case "$cur" in
1129        --*)
1130                __gitcomp "
1131                        --max-count= --max-age= --since= --after=
1132                        --min-age= --before= --until=
1133                        --no-merges
1134                        --author= --committer= --grep=
1135                        --all-match
1136                        --not --all
1137                        --numbered --summary
1138                        "
1139                return
1140                ;;
1141        esac
1142        __git_complete_revlist
1143}
1144
1145_git_show ()
1146{
1147        local cur="${COMP_WORDS[COMP_CWORD]}"
1148        case "$cur" in
1149        --pretty=*)
1150                __gitcomp "
1151                        oneline short medium full fuller email raw
1152                        " "" "${cur##--pretty=}"
1153                return
1154                ;;
1155        --*)
1156                __gitcomp "--pretty="
1157                return
1158                ;;
1159        esac
1160        __git_complete_file
1161}
1162
1163_git_stash ()
1164{
1165        local subcommands='save list show apply clear drop pop create'
1166        local subcommand="$(__git_find_subcommand "$subcommands")"
1167        if [ -z "$subcommand" ]; then
1168                __gitcomp "$subcommands"
1169        else
1170                local cur="${COMP_WORDS[COMP_CWORD]}"
1171                case "$subcommand,$cur" in
1172                save,--*)
1173                        __gitcomp "--keep-index"
1174                        ;;
1175                *)
1176                        COMPREPLY=()
1177                        ;;
1178                esac
1179        fi
1180}
1181
1182_git_submodule ()
1183{
1184        __git_has_doubledash && return
1185
1186        local subcommands="add status init update"
1187        if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1188                local cur="${COMP_WORDS[COMP_CWORD]}"
1189                case "$cur" in
1190                --*)
1191                        __gitcomp "--quiet --cached"
1192                        ;;
1193                *)
1194                        __gitcomp "$subcommands"
1195                        ;;
1196                esac
1197                return
1198        fi
1199}
1200
1201_git_svn ()
1202{
1203        local subcommands="
1204                init fetch clone rebase dcommit log find-rev
1205                set-tree commit-diff info create-ignore propget
1206                proplist show-ignore show-externals
1207                "
1208        local subcommand="$(__git_find_subcommand "$subcommands")"
1209        if [ -z "$subcommand" ]; then
1210                __gitcomp "$subcommands"
1211        else
1212                local remote_opts="--username= --config-dir= --no-auth-cache"
1213                local fc_opts="
1214                        --follow-parent --authors-file= --repack=
1215                        --no-metadata --use-svm-props --use-svnsync-props
1216                        --log-window-size= --no-checkout --quiet
1217                        --repack-flags --user-log-author $remote_opts
1218                        "
1219                local init_opts="
1220                        --template= --shared= --trunk= --tags=
1221                        --branches= --stdlayout --minimize-url
1222                        --no-metadata --use-svm-props --use-svnsync-props
1223                        --rewrite-root= $remote_opts
1224                        "
1225                local cmt_opts="
1226                        --edit --rmdir --find-copies-harder --copy-similarity=
1227                        "
1228
1229                local cur="${COMP_WORDS[COMP_CWORD]}"
1230                case "$subcommand,$cur" in
1231                fetch,--*)
1232                        __gitcomp "--revision= --fetch-all $fc_opts"
1233                        ;;
1234                clone,--*)
1235                        __gitcomp "--revision= $fc_opts $init_opts"
1236                        ;;
1237                init,--*)
1238                        __gitcomp "$init_opts"
1239                        ;;
1240                dcommit,--*)
1241                        __gitcomp "
1242                                --merge --strategy= --verbose --dry-run
1243                                --fetch-all --no-rebase $cmt_opts $fc_opts
1244                                "
1245                        ;;
1246                set-tree,--*)
1247                        __gitcomp "--stdin $cmt_opts $fc_opts"
1248                        ;;
1249                create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1250                show-externals,--*)
1251                        __gitcomp "--revision="
1252                        ;;
1253                log,--*)
1254                        __gitcomp "
1255                                --limit= --revision= --verbose --incremental
1256                                --oneline --show-commit --non-recursive
1257                                --authors-file=
1258                                "
1259                        ;;
1260                rebase,--*)
1261                        __gitcomp "
1262                                --merge --verbose --strategy= --local
1263                                --fetch-all $fc_opts
1264                                "
1265                        ;;
1266                commit-diff,--*)
1267                        __gitcomp "--message= --file= --revision= $cmt_opts"
1268                        ;;
1269                info,--*)
1270                        __gitcomp "--url"
1271                        ;;
1272                *)
1273                        COMPREPLY=()
1274                        ;;
1275                esac
1276        fi
1277}
1278
1279_git_tag ()
1280{
1281        local i c=1 f=0
1282        while [ $c -lt $COMP_CWORD ]; do
1283                i="${COMP_WORDS[c]}"
1284                case "$i" in
1285                -d|-v)
1286                        __gitcomp "$(__git_tags)"
1287                        return
1288                        ;;
1289                -f)
1290                        f=1
1291                        ;;
1292                esac
1293                c=$((++c))
1294        done
1295
1296        case "${COMP_WORDS[COMP_CWORD-1]}" in
1297        -m|-F)
1298                COMPREPLY=()
1299                ;;
1300        -*|tag|git-tag)
1301                if [ $f = 1 ]; then
1302                        __gitcomp "$(__git_tags)"
1303                else
1304                        COMPREPLY=()
1305                fi
1306                ;;
1307        *)
1308                __gitcomp "$(__git_refs)"
1309                ;;
1310        esac
1311}
1312
1313_git ()
1314{
1315        local i c=1 command __git_dir
1316
1317        while [ $c -lt $COMP_CWORD ]; do
1318                i="${COMP_WORDS[c]}"
1319                case "$i" in
1320                --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1321                --bare)      __git_dir="." ;;
1322                --version|--help|-p|--paginate) ;;
1323                *) command="$i"; break ;;
1324                esac
1325                c=$((++c))
1326        done
1327
1328        if [ -z "$command" ]; then
1329                case "${COMP_WORDS[COMP_CWORD]}" in
1330                --*=*) COMPREPLY=() ;;
1331                --*)   __gitcomp "
1332                        --paginate
1333                        --no-pager
1334                        --git-dir=
1335                        --bare
1336                        --version
1337                        --exec-path
1338                        --work-tree=
1339                        --help
1340                        "
1341                        ;;
1342                *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
1343                esac
1344                return
1345        fi
1346
1347        local expansion=$(__git_aliased_command "$command")
1348        [ "$expansion" ] && command="$expansion"
1349
1350        case "$command" in
1351        am)          _git_am ;;
1352        add)         _git_add ;;
1353        apply)       _git_apply ;;
1354        bisect)      _git_bisect ;;
1355        bundle)      _git_bundle ;;
1356        branch)      _git_branch ;;
1357        checkout)    _git_checkout ;;
1358        cherry)      _git_cherry ;;
1359        cherry-pick) _git_cherry_pick ;;
1360        commit)      _git_commit ;;
1361        config)      _git_config ;;
1362        describe)    _git_describe ;;
1363        diff)        _git_diff ;;
1364        fetch)       _git_fetch ;;
1365        format-patch) _git_format_patch ;;
1366        gc)          _git_gc ;;
1367        log)         _git_log ;;
1368        ls-remote)   _git_ls_remote ;;
1369        ls-tree)     _git_ls_tree ;;
1370        merge)       _git_merge;;
1371        merge-base)  _git_merge_base ;;
1372        name-rev)    _git_name_rev ;;
1373        pull)        _git_pull ;;
1374        push)        _git_push ;;
1375        rebase)      _git_rebase ;;
1376        remote)      _git_remote ;;
1377        reset)       _git_reset ;;
1378        shortlog)    _git_shortlog ;;
1379        show)        _git_show ;;
1380        show-branch) _git_log ;;
1381        stash)       _git_stash ;;
1382        submodule)   _git_submodule ;;
1383        svn)         _git_svn ;;
1384        tag)         _git_tag ;;
1385        whatchanged) _git_log ;;
1386        *)           COMPREPLY=() ;;
1387        esac
1388}
1389
1390_gitk ()
1391{
1392        __git_has_doubledash && return
1393
1394        local cur="${COMP_WORDS[COMP_CWORD]}"
1395        local g="$(git rev-parse --git-dir 2>/dev/null)"
1396        local merge=""
1397        if [ -f $g/MERGE_HEAD ]; then
1398                merge="--merge"
1399        fi
1400        case "$cur" in
1401        --*)
1402                __gitcomp "--not --all $merge"
1403                return
1404                ;;
1405        esac
1406        __git_complete_revlist
1407}
1408
1409complete -o default -o nospace -F _git git
1410complete -o default -o nospace -F _gitk gitk
1411complete -o default -o nospace -F _git_am git-am
1412complete -o default -o nospace -F _git_apply git-apply
1413complete -o default -o nospace -F _git_bisect git-bisect
1414complete -o default -o nospace -F _git_branch git-branch
1415complete -o default -o nospace -F _git_bundle git-bundle
1416complete -o default -o nospace -F _git_checkout git-checkout
1417complete -o default -o nospace -F _git_cherry git-cherry
1418complete -o default -o nospace -F _git_cherry_pick git-cherry-pick
1419complete -o default -o nospace -F _git_commit git-commit
1420complete -o default -o nospace -F _git_describe git-describe
1421complete -o default -o nospace -F _git_diff git-diff
1422complete -o default -o nospace -F _git_fetch git-fetch
1423complete -o default -o nospace -F _git_format_patch git-format-patch
1424complete -o default -o nospace -F _git_gc git-gc
1425complete -o default -o nospace -F _git_log git-log
1426complete -o default -o nospace -F _git_ls_remote git-ls-remote
1427complete -o default -o nospace -F _git_ls_tree git-ls-tree
1428complete -o default -o nospace -F _git_merge git-merge
1429complete -o default -o nospace -F _git_merge_base git-merge-base
1430complete -o default -o nospace -F _git_name_rev git-name-rev
1431complete -o default -o nospace -F _git_pull git-pull
1432complete -o default -o nospace -F _git_push git-push
1433complete -o default -o nospace -F _git_rebase git-rebase
1434complete -o default -o nospace -F _git_config git-config
1435complete -o default -o nospace -F _git_remote git-remote
1436complete -o default -o nospace -F _git_reset git-reset
1437complete -o default -o nospace -F _git_shortlog git-shortlog
1438complete -o default -o nospace -F _git_show git-show
1439complete -o default -o nospace -F _git_stash git-stash
1440complete -o default -o nospace -F _git_submodule git-submodule
1441complete -o default -o nospace -F _git_svn git-svn
1442complete -o default -o nospace -F _git_log git-show-branch
1443complete -o default -o nospace -F _git_tag git-tag
1444complete -o default -o nospace -F _git_log git-whatchanged
1445
1446# The following are necessary only for Cygwin, and only are needed
1447# when the user has tab-completed the executable name and consequently
1448# included the '.exe' suffix.
1449#
1450if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1451complete -o default -o nospace -F _git_add git-add.exe
1452complete -o default -o nospace -F _git_apply git-apply.exe
1453complete -o default -o nospace -F _git git.exe
1454complete -o default -o nospace -F _git_branch git-branch.exe
1455complete -o default -o nospace -F _git_bundle git-bundle.exe
1456complete -o default -o nospace -F _git_cherry git-cherry.exe
1457complete -o default -o nospace -F _git_describe git-describe.exe
1458complete -o default -o nospace -F _git_diff git-diff.exe
1459complete -o default -o nospace -F _git_format_patch git-format-patch.exe
1460complete -o default -o nospace -F _git_log git-log.exe
1461complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
1462complete -o default -o nospace -F _git_merge_base git-merge-base.exe
1463complete -o default -o nospace -F _git_name_rev git-name-rev.exe
1464complete -o default -o nospace -F _git_push git-push.exe
1465complete -o default -o nospace -F _git_config git-config
1466complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1467complete -o default -o nospace -F _git_show git-show.exe
1468complete -o default -o nospace -F _git_log git-show-branch.exe
1469complete -o default -o nospace -F _git_tag git-tag.exe
1470complete -o default -o nospace -F _git_log git-whatchanged.exe
1471fi