Code

Merge branch 'maint-1.5.6' into maint-1.6.0
[git.git] / contrib / completion / git-completion.bash
index 2f8036d1d914ea54e4eabae3afbdca5f4a06ab43..8fc01fb4971d80a92712aaf5306fce59ece564be 100755 (executable)
@@ -271,15 +271,17 @@ __git_merge_strategies ()
                echo "$__git_merge_strategylist"
                return
        fi
-       sed -n "/^all_strategies='/{
-               s/^all_strategies='//
-               s/'//
+       git merge -s help 2>&1 |
+       sed -n -e '/[Aa]vailable strategies are: /,/^$/{
+               s/\.$//
+               s/.*://
+               s/^[    ]*//
+               s/[     ]*$//
                p
-               q
-               }" "$(git --exec-path)/git-merge"
+       }'
 }
 __git_merge_strategylist=
-__git_merge_strategylist="$(__git_merge_strategies 2>/dev/null)"
+__git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
 
 __git_complete_file ()
 {
@@ -384,7 +386,9 @@ __git_porcelain_commands ()
                cat-file)         : plumbing;;
                check-attr)       : plumbing;;
                check-ref-format) : plumbing;;
+               checkout-index)   : plumbing;;
                commit-tree)      : plumbing;;
+               count-objects)    : infrequent;;
                cvsexportcommit)  : export;;
                cvsimport)        : import;;
                cvsserver)        : daemon;;
@@ -393,6 +397,7 @@ __git_porcelain_commands ()
                diff-index)       : plumbing;;
                diff-tree)        : plumbing;;
                fast-import)      : import;;
+               fast-export)      : export;;
                fsck-objects)     : plumbing;;
                fetch-pack)       : plumbing;;
                fmt-merge-msg)    : plumbing;;
@@ -402,6 +407,10 @@ __git_porcelain_commands ()
                index-pack)       : plumbing;;
                init-db)          : deprecated;;
                local-fetch)      : plumbing;;
+               lost-found)       : infrequent;;
+               ls-files)         : plumbing;;
+               ls-remote)        : plumbing;;
+               ls-tree)          : plumbing;;
                mailinfo)         : plumbing;;
                mailsplit)        : plumbing;;
                merge-*)          : plumbing;;
@@ -426,6 +435,7 @@ __git_porcelain_commands ()
                runstatus)        : plumbing;;
                sh-setup)         : internal;;
                shell)            : daemon;;
+               show-ref)         : plumbing;;
                send-pack)        : plumbing;;
                show-index)       : plumbing;;
                ssh-*)            : transport;;
@@ -440,6 +450,8 @@ __git_porcelain_commands ()
                upload-archive)   : plumbing;;
                upload-pack)      : plumbing;;
                write-tree)       : plumbing;;
+               var)              : infrequent;;
+               verify-pack)      : infrequent;;
                verify-tag)       : plumbing;;
                *) echo $i;;
                esac
@@ -638,21 +650,12 @@ _git_branch ()
 
 _git_bundle ()
 {
-       local mycword="$COMP_CWORD"
-       case "${COMP_WORDS[0]}" in
-       git)
-               local cmd="${COMP_WORDS[2]}"
-               mycword="$((mycword-1))"
-               ;;
-       git-bundle*)
-               local cmd="${COMP_WORDS[1]}"
-               ;;
-       esac
-       case "$mycword" in
-       1)
+       local cmd="${COMP_WORDS[2]}"
+       case "$COMP_CWORD" in
+       2)
                __gitcomp "create list-heads verify unbundle"
                ;;
-       2)
+       3)
                # looking for a file
                ;;
        *)
@@ -738,7 +741,7 @@ _git_commit ()
        --*)
                __gitcomp "
                        --all --author= --signoff --verify --no-verify
-                       --edit --amend --include --only
+                       --edit --amend --include --only --interactive
                        "
                return
        esac
@@ -769,7 +772,7 @@ _git_diff ()
                __gitcomp "--cached --stat --numstat --shortstat --summary
                        --patch-with-stat --name-only --name-status --color
                        --no-color --color-words --no-renames --check
-                       --full-index --binary --abbrev --diff-filter
+                       --full-index --binary --abbrev --diff-filter=
                        --find-copies-harder --pickaxe-all --pickaxe-regex
                        --text --ignore-space-at-eol --ignore-space-change
                        --ignore-all-space --exit-code --quiet --ext-diff
@@ -787,14 +790,9 @@ _git_fetch ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
 
-       case "${COMP_WORDS[0]},$COMP_CWORD" in
-       git-fetch*,1)
+       if [ "$COMP_CWORD" = 2 ]; then
                __gitcomp "$(__git_remotes)"
-               ;;
-       git,2)
-               __gitcomp "$(__git_remotes)"
-               ;;
-       *)
+       else
                case "$cur" in
                *:*)
                        local pfx=""
@@ -805,16 +803,10 @@ _git_fetch ()
                        __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}"
                        ;;
                *)
-                       local remote
-                       case "${COMP_WORDS[0]}" in
-                       git-fetch) remote="${COMP_WORDS[1]}" ;;
-                       git)       remote="${COMP_WORDS[2]}" ;;
-                       esac
-                       __gitcomp "$(__git_refs2 "$remote")"
+                       __gitcomp "$(__git_refs2 "${COMP_WORDS[2]}")"
                        ;;
                esac
-               ;;
-       esac
+       fi
 }
 
 _git_format_patch ()
@@ -885,7 +877,11 @@ _git_help ()
                return
                ;;
        esac
-       __gitcomp "$(__git_all_commands)"
+       __gitcomp "$(__git_all_commands)
+               attributes cli core-tutorial cvs-migration
+               diffcore gitk glossary hooks ignore modules
+               repository-layout tutorial tutorial-2
+               "
 }
 
 _git_init ()
@@ -941,6 +937,11 @@ _git_log ()
        __git_has_doubledash && return
 
        local cur="${COMP_WORDS[COMP_CWORD]}"
+       local g="$(git rev-parse --git-dir 2>/dev/null)"
+       local merge=""
+       if [ -f "$g/MERGE_HEAD" ]; then
+               merge="--merge"
+       fi
        case "$cur" in
        --pretty=*)
                __gitcomp "
@@ -972,6 +973,7 @@ _git_log ()
                        --decorate --diff-filter=
                        --color-words --walk-reflogs
                        --parents --children --full-history
+                       $merge
                        "
                return
                ;;
@@ -1046,51 +1048,29 @@ _git_pull ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
 
-       case "${COMP_WORDS[0]},$COMP_CWORD" in
-       git-pull*,1)
-               __gitcomp "$(__git_remotes)"
-               ;;
-       git,2)
+       if [ "$COMP_CWORD" = 2 ]; then
                __gitcomp "$(__git_remotes)"
-               ;;
-       *)
-               local remote
-               case "${COMP_WORDS[0]}" in
-               git-pull)  remote="${COMP_WORDS[1]}" ;;
-               git)       remote="${COMP_WORDS[2]}" ;;
-               esac
-               __gitcomp "$(__git_refs "$remote")"
-               ;;
-       esac
+       else
+               __gitcomp "$(__git_refs "${COMP_WORDS[2]}")"
+       fi
 }
 
 _git_push ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
 
-       case "${COMP_WORDS[0]},$COMP_CWORD" in
-       git-push*,1)
-               __gitcomp "$(__git_remotes)"
-               ;;
-       git,2)
+       if [ "$COMP_CWORD" = 2 ]; then
                __gitcomp "$(__git_remotes)"
-               ;;
-       *)
+       else
                case "$cur" in
                *:*)
-                       local remote
-                       case "${COMP_WORDS[0]}" in
-                       git-push)  remote="${COMP_WORDS[1]}" ;;
-                       git)       remote="${COMP_WORDS[2]}" ;;
-                       esac
-
                        local pfx=""
                        case "$COMP_WORDBREAKS" in
                        *:*) : great ;;
                        *)   pfx="${cur%%:*}:" ;;
                        esac
 
-                       __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}"
+                       __gitcomp "$(__git_refs "${COMP_WORDS[2]}")" "$pfx" "${cur#*:}"
                        ;;
                +*)
                        __gitcomp "$(__git_refs)" + "${cur#+}"
@@ -1099,8 +1079,7 @@ _git_push ()
                        __gitcomp "$(__git_refs)"
                        ;;
                esac
-               ;;
-       esac
+       fi
 }
 
 _git_rebase ()
@@ -1370,7 +1349,7 @@ _git_revert ()
                return
                ;;
        esac
-       COMPREPLY=()
+       __gitcomp "$(__git_refs)"
 }
 
 _git_rm ()
@@ -1411,6 +1390,8 @@ _git_shortlog ()
 
 _git_show ()
 {
+       __git_has_doubledash && return
+
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --pretty=*)
@@ -1590,7 +1571,7 @@ _git_tag ()
        -m|-F)
                COMPREPLY=()
                ;;
-       -*|tag|git-tag)
+       -*|tag)
                if [ $f = 1 ]; then
                        __gitcomp "$(__git_tags)"
                else
@@ -1700,7 +1681,7 @@ _gitk ()
        local cur="${COMP_WORDS[COMP_CWORD]}"
        local g="$(git rev-parse --git-dir 2>/dev/null)"
        local merge=""
-       if [ -f $g/MERGE_HEAD ]; then
+       if [ -f "$g/MERGE_HEAD" ]; then
                merge="--merge"
        fi
        case "$cur" in